/*-------------最佳置换算法(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]==
最佳置换算法 来自淘豆网www.taodocs.com转载请标明出处.