/*
* memory.c
*
* Created on: Jun 9, 2010
* Author: WangYun
*/
#include<stdio.h>
#define PAGE_NUM 20
#define BLOCK 3
void get_page(int page_seq[])
{
int i=PAGE_NUM;
printf("Please input %d numbers,which is the sequence of page number "
"such as(7 0 1 8 ...)\n",i);
for(i=0;i<PAGE_NUM;i++)
scanf("%d",&page_seq[i]);
}
int sum_found(int found[])
{
int i;
int sum=0;
for(i=0;i<BLOCK;i++)
sum+=found[i];
return sum;
}
int opt(int page_seq[])
{
int p;
int i,j;
int found[BLOCK]={0};
int block[BLOCK];
int lack=0;
for(i=0;i<BLOCK;i++) /*Initiate the physical block*/
block[i]=-1;
for(i=0;i<PAGE_NUM;i++)
{
for(p=0;p<BLOCK;p++)
found[p]=0;
for(p=0;p<BLOCK;p++)
if(block[p]==page_seq[i])
break;
if(p==BLOCK) /*Not find the page in the physical b
页面置换算法(FIFO,LRU,OPT)c模拟
最新推荐文章于 2024-06-09 23:21:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)