#include< stdio.h>
#include< conio.h>
void main()
{
int page[20],n,f,i,j,a[20],pf=0,match,index,counter=0,count[20];
clrscr();
printf("enter the length of the reference string");
scanf("%d",&n);
printf("enter the frame size");
scanf("%d",&f);
printf("enter reference string");
for(i=0;i< n;i++)
scanf("%d",&page[i]);
for(j=0;j< f;j++)
a[j]=-1;
printf("\n-1\t-1\t-1\n\n");
for(i=0;i< n;i++)
{
match=0;
for(j=0;j< f;j++)
if(a[j]==page[i])
{
match=1;
counter++;
count[j]=counter;
}
if(match==1)
{
goto x;
}
for(j=0;j< f;j++)
if(a[j]==-1)
{
a[j]=page[i];
counter++;
count[j]=counter;
pf++;
goto x;
}
index=0;
for(j=0;j< f;j++)
{
if(count[j]< count[index])
{
index=j;
}
}
a[index]=page[i];
counter++;
count[index]=counter;
pf++;
x:;
for(j=0;j< f;j++)
printf("%d \t",a[j]);
printf("\n\n");
}
printf("no of page faults are %d",pf);
getch();
}
0 comments:
Post a Comment