package proj;
import java.util.PriorityQueue;
public class LRU {
private int size;
private String[] memory;
private String address;
private int count = 0;
public LRU(int size) {
this.size = size;
memory = new String[size];
}
public void addLRU(String address) {
this.address = address;
if(contains(address)) {
for(int i=0;i<memory.length;i++) {
if(address.equals(memory[i])) {
String str = memory[i];
for(int j=i;j>0;j--) {
memory[j] = memory[j-1];
}
memory[0]=str;
return;
}
}
} else {
count++;
for(int j=size-1;j>0;j--) {
memory[j] = memory[j-1];
}
memory[0]=address;
}
}
private boolean contains(String address) {
for(int i=0;i<size;i++) {
if(address.equals(memory[i]))
return true;
}
return false;
}
public String toString() {
String str = "页面"+address+"调入: ";
for(int i=0;i<size;i++) {
str = str +"|"+ memory[i];
}
return str+"|";
}
public int interrupt() {
return count;
}
}
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。