- 1、本文档共7页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
页面置换算法(FIFO算法,LRU算法)
实验四 页面置换算法
实验流程图
实验程序
#include stdio.h
#include stdlib.h
#include malloc.h
#define null 0
#define len sizeof(struct page)
struct page
{ int num;
int tag;
struct page *next;
};
struct page *create(int n) /*建立分配的内存空间,并初始化,返回头结点*/
{int count=1;
struct page *p1,*p2,*head;
head=p2=p1=(struct page *)malloc(len); //开辟一个新的单元,并将malloc返回的指针转换为结构体类型的指针
p1-tag=-1;p1-num=-1;
while(countn)
{count++;
p1=(struct page *)malloc(len);
p1-tag=-1;p1-num=-1;
p2-next=p1;
p2=p1;
}
p2-next=null;
return(head);
}
void FIFO(int array[],int n)
{int *p;
struct page *cp,*dp,*head,*new1;
int count=0;
head=create(n);
p=array;
while(*p!=-1)
{ cp=dp=head;
for(;cp-num!=*pcp-next!=null;) cp=cp-next;
if (cp-num==*p) printf( ! );
else
{ count++;
cp=head;
for(;cp-tag!=-1cp-next!=null;) cp=cp-next;
if(cp-tag==-1)
{cp-num=*p;
cp-tag=0;
printf( * );
}
else
{new1=(struct page*)malloc(len);
new1-num=*p;
new1-tag=0;
new1-next=null;
cp-next=new1;
head=head-next;
printf( %d ,dp-num);
free(dp);
}
}
p++;
}
printf(\nQueye Zongshu : %d \n,count);
}
void LRU(int array[],int n)
{int count=0,*p=array;
struct page *head,*cp,*dp,*rp,*new1,*endp;
head=create(n);
while(*p!=-1)
{cp=dp=rp=endp=head;
for(;endp-next!=null;) endp=endp-next;
for(;cp-num!=*pcp-next!=null;)
{rp=cp;cp=cp-next;}
if(cp-num==*p)
{printf( ! );
if(cp-next!=null)
{if(cp!=head)
rp-next=cp-next;
else head=head-next;
}
endp-next=cp;
cp-next=null;
}
else
{count++;
cp=rp=head;
for(;cp-tag!=-1cp-next!=null;) cp=cp-next;
if(cp-tag==-1)
{printf( * );
cp-num=*p;
cp-tag=0;
}
else
{new1=(struct page *)malloc(len);
new1-num=*p;
new1-tag=0;
new1-next=null;
cp-next=new1;
dp=head;
head=head-n
您可能关注的文档
- 阅读材料——16健康:防酗酒装置.doc
- 阅读短文并在粗体字中找出在句中作谓语的过去分词(填.doc
- 防弹玻璃玻璃行业标准介绍(doc ).doc
- 防抱死系统在常用轿车上的使用特点分1.doc
- 防止机组非计划停运措施(电气专业).doc
- 防波堤钓的思与行(下).doc
- 防火门、防火卷帘门合同(BOPP最终版本)[教育].doc
- 防爆电器产品型号的编制方1.doc
- 防盗安全门产品认证实施规则(CSP-V01-001).doc
- 阳光海岸海鲜荟员工手册2.doc
- 制动系统的特点项目一58课件.pptx
- 直接工程费价外运杂费填料费铁路工程施工组织与概预算78课件.pptx
- 主备用控制中心的切换LCF300型25课件.pptx
- 智能交通系统的相关技术任务三车辆自动驾驶技术王怡安徽交通6.pptx
- 智能交通监控系统任务三城市交通诱导系统诱导系统的组成王怡安.pptx
- 智能交通监控系统任务二城市交通监控系统王怡安徽交通67课件.pptx
- 直升机的特点和分类空气动力学基础与飞行原理86课件.ppt
- 直升机的飞行性能空气动力学基础与飞行原理67课件.ppt
- 职业形象塑造3职业教育国际邮轮乘务管理专业教学化妆与形象设.pptx
- 轴向拉压杆件的线应变和胡克定律张亚琴河北交通52课件.pptx
最近下载
- 基于智能化技术的供水管网漏点判定与修复管理模式.pptx
- 2023-2024学年沪科版(2019)高中信息技术必修二第三单元项目五《规划并连接数字家庭系统的网络——组建小型信息系统网络(一)》说课稿.docx VIP
- 北京市城镇供水厂生产安全事故隐患目录.pdf VIP
- 业主委员会委员候选人推荐表.docx VIP
- NB-T35003-2023水电工程水情自动测报系统技术规范.pdf VIP
- 2025年高考英语陕西卷含解析及答案.docx VIP
- 2025年管道直饮水项目可行性研究报告.docx
- 地理信息安全在线培训考试题目完整版答案.docx
- 幼儿园区域活动的实施策略.pptx
- 10kV及以下变电所设计规范.pdf VIP
文档评论(1)