码迷,mamicode.com
首页 > 编程语言 > 详细

FIFO页面置换算法

时间:2016-06-23 22:19:33      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

本文以序列长度20的{ 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1};以及页面4;为例;

 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,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1};
 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         else
20             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("输出结果为下表(-1代表为空,*代表有缺页):\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 }

结果:

技术分享

FIFO页面置换算法

标签:

原文地址:http://www.cnblogs.com/ABook/p/5612296.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!