program to implement FIFO algorithm in JAVA


import java.io.*;
class fifo
{
public static void main(String []st)throws IOException
{
int pf=0,hits=0,i,j;
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter no of pages=>");
int p=Integer.parseInt(b.readLine());
int page_no[]=new int[p];
System.out.println("Enter no. of pages in page frame");
int m=Integer.parseInt(b.readLine());
int page_frame[]=new int[m];
int pointer=0,hit=0;
for(i=0;i
{
System.out.println("Enter "+(i+1)+" page no.");
page_no[i]=Integer.parseInt(b.readLine());
}
for(i=0;i page_frame[i]=page_no[i];

for(i=0;i System.out.print(page_frame[i]+" ");
for(i=m;i
{
for(j=0;j {
if(page_frame[j]==page_no[i])
{
hits++;
hit=1;
System.out.println();
for(int k=0;k System.out.print(page_frame[k]+" ");
}
}
if(hit==0)
{
page_frame[pointer]=page_no[i];
pointer++;
if(pointer==m)
pointer=0;
pf++;
System.out.println();
for(int k=0;k System.out.print(page_frame[k]+" ");
}
hit=0;
}
System.out.println("\nNo. of hits "+hits);
System.out.println("No. of pf "+(pf+1));
}
}

0 comments :