作業系統之動態分割槽分配演算法
class Block{
private int number;
private char course;
private int size;
private int begin;
boolean flag;
Block next;
public Block(){
number = 0;
course = '#';
size = 0;
begin = 0;
flag = false;
next = null;
}
public Block(int num,char course,int size,int begin,boolean flag){
number = num;
num ++;
this.course = course;
this.size = size;
this.begin = begin;
this.flag = flag;
}
public void show(){
System.out.print(" "+this.number+" ");
if(this.course == '#')
System.out.print(" "); //9
else
System.out.print(" "+this.course+" ");
System.out.print(" "+this.size +" "+ this.begin);
if(!this.flag) System.out.print(" 空閒 \n");
else System.out.print(" 佔用 \n");
if(this.next != null){
this.next.show();
}
}
public Block search(int a){ //查詢符合的空間節點
if(this.flag == false&&this.size >= a){
return this;
}
else if(this.next!=null){
return this.next.search(a);
}
return null;
}
public void add(int num,char c,int a,Block root){
if(this.next == null){
Block temp = root.search(a);
if(temp == null){
System.out.println("記憶體不足!");
}
else{
if(temp.size - a < 10)
a = temp.size;
this.next = new Block(num,c,a,temp.begin,true);
temp.size = temp.size - a;
temp.begin = temp.begin + a;
}
}
else{
this.next.add(num,c,a,root);
}
}
public void clean(char ch){
if(this.course == ch){