1 / 3
文档名称:

最佳置换算法.doc

格式:doc   大小:119KB   页数:3页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

最佳置换算法.doc

上传人:mkjafow 2020/8/7 文件大小:119 KB

下载得到文件列表

最佳置换算法.doc

文档介绍

文档介绍:/*-------------最佳置换算法(OPtimalReplacementAlgorithm,ORA)-------------*//*算法描述:所选择的淘汰页,是以后永不使用,或最长时间内不使用的页面*//*---------------------------------writenbyXuZhuozhuo-----------------------------------*/C++代码示例:#include<iostream>#defineMaxSize20#defineNum_Block3usingnamespacestd;intmax(inta,intb,intc)//返回三者的最大值{if(a<b)a=b;if(a<c)a=c; returna;}intmain(){intnum_ref; //引用字符的数目intref_arr[MaxSize];//引用字符串数组intphy_blk[Num_Block];//数组模拟“物理块”cout<<"-----OptimalReplacementAlgorithms-----"<<endl<<endl;do{ cout<<"Pleaseinputthenumberofreferencechars:"<<endl; cin>>num_ref;//输入引用字符串的数目}while(num_ref>MaxSize);cout<<"Pleaseinputthequeueofreferencechars:"<<endl;for(inti=0;i<num_ref;i++)//输入引用字符串的队列cin>>ref_arr[i];for(intj=0;j<Num_Block;j++)//前Num_Block项进物理块phy_blk[j]=ref_arr[j];cout<<endl<<"Displaythereplacementprocedure:";cout<<endl<<"----------------------------------"<<endl;for(intp=0;p<num_ref-Num_Block;p++){ if(!(phy_blk[0]==ref_arr[Num_Block+p]||phy_blk[1]==ref_arr[Num_Block+p]||phy_blk[2]==ref_arr[Num_Block+p])){//寻找phy_blk[0]在引用字符串中的下一位置k1for(intk1=Num_Block+p+1;k1<MaxSize;k1++)if(phy_blk[0]==ref_arr[k1])break;//寻找phy_blk[1]在引用字符串中的下一位置k2for(intk2=Num_Block+p+1;k2<MaxSize;k2++)if(phy_blk[1]==