C program to implement FIFO Page Replacement Algorithm
#include<stdio.h>
#include<conio.h>
main()
{
int str[100],n,f;
int index,point,i,j,ch,min,max=0,mem[10][10],count=0;
printf("\n Enter the number of entries:\n");
scanf("%d",&n);
printf("\n Enter the elements:\n");
for(i=0;i<n;i++)
scanf("%d",&str[i]);
printf("Enter the number of frames:");
scanf("%d",&f);
for(i=0;i<f;i++)
{
mem[i][0]=-1;
mem[i][1]=0;
}
for(i=0;i<n;i++)
{
point=0;
for(j=0;j<f;j++)
{
if(mem[j][0]==str[i])
point=1;
}
if(point==1)
{
printf("\n");
continue;
}
point=0;
count++;
for(j=0;j<f;j++)
{
if(mem[j][0]==-1)
{
point=1;
break;
}
}
if(point==1)
{
mem[j][0]=str[i];
mem[j][1]=i;
printf("\n");
for(j=0;j<f&&mem[j][0]!=-1;j++)
printf("%d ",mem[j][0]);
printf("\n");
continue;
}
else
{
min=9999;
for(j=0;j<f;j++)
{
if(min>mem[j][1])
{
min=mem[j][1];
index=j;
}
}
mem[index][0]=str[i];
mem[index][1]=i;
for(j=0;j<f&&mem[j][0]!=-1;j++)
{
printf("%d ",mem[j][0]);
printf("\n");
}
}
}
printf("\n Page Fault=%d\n",count);
}
No comments:
Post a Comment