This program Implements FIFO using queue
Input: String and no of Page Frames
Output: Displays no of Page Faults
******************************************************************/
Note: Replace text in Red with respective symbols
#include "stdio.h"
#include "string.h"
int main()
{
int p,front=0,rear=-1,len,i,j=0,flag=0,pf=0;
char a[10];
//Enter the String
printf("Enter the string\n");
gets(a);
//No of Page Frames
printf("Enter the no of page frames\n");
scanf("%d",&p);
//create a queue
char q[p];
//implement queue
len=strlen(a);
for(i=0;i less than len;i++)
{
while(j less than len)
{
if(a[i]==q[j])
flag=1;
j++;
}
if(flag==0)
{
pf++;
if(rear less than len)
q[rear++]=a[i];
else
{
q[front]=0;
front++;
rear=0;
q[rear]=a[i];
}
}
if(front==len)
front=0;
flag=0;
j=0;
}
printf("No of page faults\n%d",pf);
return 0;
}
No comments:
Post a Comment