辅导FIFO数据结构、辅导JAVA FIFO程序、讲解java FIFO
- 首页 >> C/C++编程package proj;
public class FIFO {
private int size;
private String[] memory1;
private String address;
private int count = 0;
public FIFO(int size) {
this.size = size;
memory1 = new String[size];
}
public void addFIFO(String address) {
this.address = address;
String[] memory_ = new String[size];
if(contains(address)) {
return;
} else {
count++;
memory_[0] = address;
for(int i=0;i<size-1;i++) {
memory_[i+1] = memory1[i];
}
memory1 = memory_;
}
//for(int i=0;i<size-1;i++) {
//if(memory1[i]==null){
//String st="0";
//memory1[i]=st;
//}
//}
}
private boolean contains(String address) {
for(int i=0;i<size;i++) {
if(address.equals(memory1[i]))
return true;
}
return false;
}
public String toString() {
String str = "页面"+address+"调入"+":";
for(int i=0;i<size;i++) {
str = str +"|"+ memory1[i];
}
return str+"|";
}
public int interrupt() {
return count;
}
}