用java语言实现LRU算法和FIFO算法。急急急!!!!!!!

要求是给出任意的输入流,计算缺页率

而且输入流长度和cache尺寸可定制。
例如:cache=5,从0-9中数字任意排序,长度为30.
输入流:12568,,36536,56892,70495,36745,87345.

您好,百度贴吧专家团很高兴能够回答您的问题。您的采纳是我们前进的动力。
public class LRU {

private int theArray[];
private int back; //定义队尾
private int currentSize; //队列中存放元素个数
private int maxSize=5; //队列中能存放元素的个数

public LRU(){
theArray=new int[maxSize];
back=0;
currentSize=0;
}
public void queue(int a[]){
for(int i=0;i<a.length;i++){
enQueue(a[i]);
}
}

public void enQueue(int x){ //入队
beUsed(x); //先判断是否已存在该页号,若存在,删除
if(currentSize<maxSize){
theArray[back]=x;
back++;
currentSize++;
}else if(currentSize==maxSize){ //满了
for(int i=0;i<maxSize-1;i++){
theArray[i]=theArray[i+1];
}
theArray[maxSize-1]=x;
}
for(int i=0;i<currentSize;i++){
System.out.print(theArray[i]);
}
System.out.println();
}
public void beUsed(int x){ //判断是否已存在该页号,若存在,删除已有的
for(int i=0;i<currentSize;i++){
if(theArray[i]==x){
for(int j=i;j<currentSize-1;j++){
theArray[j]=theArray[j+1];
}
currentSize--;
back--;
}
}
}
public static void main(String[] args) {
LRU lru=new LRU();
int a[]={4,7,0,7,1,0,1,2,1,2,6};
lru.queue(a);
}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-11-30
哈哈哈,你到底是谁,我要告诉夏天老师追问

本是同根生,相煎何太急。

ps:同学,求代码啊。。

第2个回答  2014-11-29
完全没看懂追问

就是用java语言写段程序实现操作系统中的LRU和FIFO算法,目标是能输入任意的输入流,并且能计算出缺页率。。不难懂吧。。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网