-
Notifications
You must be signed in to change notification settings - Fork 4
/
Fifo.c
58 lines (54 loc) · 947 Bytes
/
Fifo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
int search(int a[], int t, int n)
{
int i=0;
while(i<n)
{
if(a[i]==t)
return 0;
i++;
}
return 1;
}
void printstack(int stack[], int n)
{
int i=0;
for(; i<n; i++)
printf("%d ",stack[i]);
printf("\n");
}
int main()
{
printf("No of pages: ");
int pages;
scanf("%d", &pages);
printf("Lenght of string: ");
int n;
scanf("%d", &n);
int i;
int a[n];
int cnt=0;
for(i=0; i<n; i++)
scanf("%d",&a[i]);
i=0;
int j=0;
int stack[3]={-1,-1,-1};
while(i<n)
{
if(search(stack,a[i],pages))
{
printf("Page fault:%d\n", a[i]);
stack[j]=a[i];
j=(j+1)%pages;
printstack(stack,pages);
cnt++;
}
else
{
printf("Page found:%d\n",a[i]);
}
i++;
}
return 0;
}