I am doing FIFO LRU and Optimal. I have a problem for Optimal ( replace it with the one that we will not use in the longest time, so the furthest one). I got it to replace my fram number with the one that i dont use in the longest. But the problem is that when the number that i want to replace it with doesn't even exist HOW DO I STOP MY IF statesman? And im not sure which "if" to stop? i tried this:
public int toss( int pr ) 
{
// if we get the same number just return -1
for (int s=numberOfFrames-1; s>=0; s--) 
{
    // if we get the same number dont kick anything 
    if ( pr == fram[s]) 
    {
        return -1;
    }
}
// find which frame to replace
int look2 = 0; // this is the co for the number you want to replace with.
// next time it is used.
int co = 0; // this is index to pra.
int r = -1;
   for ( int d=numberOfFrames-1; d>=0; d--) 
   {
       lookFor(d,r);
   }
   if (r == -1) 
   {
       //item not found, handle however you want, one suggestion is:
       return -1;  //have the caller handle this correctly
   }
   else
   {
       int q = fram[r]; // remember 2 which is page we are getting raid off
       fram[r] = pra[co]; //  fram one we want to get raid off and replace it with the                       pr
       return q; // return the one we kicked
   }
}
int co = 0; int look2 = 0;
public int lookFor(int d, int r) {
   for( int f=co; f>=0; f++) // f looping for pra
   {
       co = tossCallCount++;
       System.out.println("here");
       if( fram[d] == pra[f])
       {
           System.out.println("by"+pra[f]);
           if(look2<=f) 
           {
               System.out.println("hi"+fram[d]);
               r = d;
               look2 = f;
               break;
           }
       }
   }
   return d;
} }
 
     
    