四种方法就不多介绍了,别的可以看,只是学生作品记录,做的地方还有许多不足
1.比如说当剩余空间Space的start = end相等时没有删除该剩余空间,反正是不想想了
2.还有的就是main方法只能理解过后才明白它在干什么,不能很清晰的设计程序步骤
3.ps:应付作业,我真可恶啊
package OS.Memory.T2;
import java.util.*;
public class Memory {
public static void main(String[] args) {
Memory memory = new Memory(20);
memory.addZone(4, 7);
memory.addZone(12, 17);
memory.calculateRest();
memory.showSpaces();
memory.allocation(3);
memory.allocation(5);
}
private int size;
//仅在领近算法时有用到
private int pointer;
private LinkedList<Zone> zones;
private List<Space> rest;
//占用空间类
class Zone {
//分区始址
private int start;
//分区终址
private int end;
//空闲状态
private boolean isFree;
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
public Zone(int start, int end) {
this.start = start;
this.end = end;
}
}
// 剩余空间类
class Space {
private int sstart;
private int send;
public Space(int sstart, int send) {
this.sstart = sstart;
this.send = send;
}
public int getSstart() {
return sstart;
}
public void setSstart(int sstart) {
this.sstart = sstart;
}
public int getSend() {