I wrote a program which implements Optimal page replacement algorithm i'm mentioning what is Optimal page replacement algorithm and the code i've written and i commented each step...

<please note that i just modified the program of FIFO written by mr. ranjith and implemented my logic where the diffrence comes>

What is optimal page replacement?
Optimal Page Replacement Algorithm.pdf

The program i written
OPTIMAL.txt

I'm getting unreachable code errors and wrong output

output must be
2 -1 -1
2 3 -1
2 3 -1
2 3 1
2 3 5
2 3 5
4 3 5
4 3 5
4 3 5
2 3 5
2 3 5
2 3 5