FIFO page replacement algorithm and fifo Algorithm
In this article, the {,} of the sequence length 20, and page 4; are used as an example;
1 # include <stdio. h> 2 3 # define InitPysiBlocks 4 4 # define MaxPages 20 5 int PysicalBlocks [InitPysiBlocks] = {-1,-1,-1,-1 }; 6 int PageSequence [MaxPages] = {,}; 7 8 void FIFO (int py [], int pg []) 9 {10 int I, q, j, table [InitPysiBlocks] [MaxPages]; 11 char flag, f [MaxPages]; 12 for (I = 0; I <MaxPages; I ++) 13 {14 q = 0; 15 while (pg [I]! = Py [q] & q! = InitPysiBlocks) 16 q ++; 17 if (q = InitPysiBlocks) 18 flag = '*'; 19 else20 flag = ''; 21 if (flag = '*') 22 {23 for (j = InitPysiBlocks-1; j> 0; j --) 24 py [j] = py [j-1]; 25 py [0] = pg [I]; 26} 27 for (j = 0; j <InitPysiBlocks; j ++) 28 table [j] [I] = py [j]; 29 f [I] = flag; 30} 31 printf ("the output result is the following table (-1 indicates null, * Indicates missing pages): \ n "); 32 for (I = 0; I <InitPysiBlocks; I ++) 33 {34 for (j = 0; j <MaxPages; j ++) 35 printf ("% 3d", table [I] [j]); 36 printf ("\ n"); 37} 38 for (I = 0; I <MaxPages; I ++) 39 printf ("% 3c", f [I]); 40 printf ("\ n"); 41} 42 43 void main () 44 {45 FIFO (PysicalBlocks, PageSequence); 46}
Result: