.
ch=p->data.length-request; }
else if(q->data.length < p->data.length) { q=p;
ch=p->data.length-request; } }
p=p->next; }
if(q==NULL) return ERROR;//ûҵп else if(q->data.length==request) {
q->data.length=1; return OK; } else {
temp->prior=q->prior; temp->next=q;
temp->data.address=q->data.address; temp->data.num=q->data.num; q->prior->next=temp; q->prior=temp;
q->data.address+=request; q->data.length=ch; q->data.num+=1; return OK; }
return OK; }
//
Status allocation(int a) {
int request;//ڴС
printf(\С(λ:KB):\ scanf(\
if(request<0 ||request==0) {
printf(\Сʣԣ\ return ERROR; }
Ʒ
.
switch(a) {
case 1: //Ĭ״Ӧ㷨
if(First_fit(request)==OK) printf(\ɹ****\ else printf(\ڴ治㣬ʧܣ****\ return OK; break;
case 2: //ѡӦ㷨
if(Best_fit(request)==OK) printf(\ɹ****\ else printf(\ڴ治㣬ʧܣ****\ return OK; break; case 3: //ѡӦ㷨
if(Worst_fit(request)==OK) printf(\ɹ****\ else printf(\ڴ治㣬ʧܣ****\ return OK; break; } }
Status deal1(Node *p)//տռ {
Node *q=first;
for(;q!=NULL;q=q->next) {
if(q==p) { if(q->prior->data.state==0&&q->next->data.state!=0) { q->prior->data.length+=q->data.length; q->prior->next=q->next; q->next->prior=q->prior; q=q->prior; q->data.state=0;
q->data.num=flag-1; }
if(q->prior->data.state!=0&&q->next->data.state==0) {
q->data.length+=q->next->data.length; q->next=q->next->next; q->next->next->prior=q; q->data.state=0;
q->data.num=flag; }
Ʒ
.
if(q->prior->data.state==0&&q->next->data.state==0) { q->prior->data.length+=q->data.length; q->prior->next=q->next; q->next->prior=q->prior; q=q->prior; q->data.state=0; q->data.num=flag-1; }
if(q->prior->data.state!=0&&q->next->data.state!=0) { q->data.state=0; } } }
return OK; }
Status deal2(Node *p)//տռ {
Node *q=first;
for(;q!=NULL;q=q->next) {
if(q==p) { if(q->prior->data.state==0&&q->next->data.state!=0) { q->prior->data.length+=q->data.length; q->prior->next=q->next; q->next->prior=q->prior; q=p->prior; q->data.state=0;
q->data.num=flag-1; }
if(q->prior->data.state!=0&&q->next->data.state==0) {
q->data.state=0; }
if(q->prior->data.state==0&&q->next->data.state==0) { q->prior->data.length+=q->data.length; q->prior->next=q->next; q->next->prior=q->prior; q=q->prior;
Ʒ
.
q->data.state=0; q->data.num=flag-1; }
if(q->prior->data.state!=0&&q->next->data.state!=0) { q->data.state=0; } } }
return OK; }
//
Status recovery(int flag) {
Node *p=first;
for(;p!=NULL;p=p->next) {
if(p->data.num==flag) { if(p->prior==first) { if(p->next!=end)//ǰPָһһʱ { if(p->next->data.state==0) //Ŀп {
p->data.length+=p->next->data.length; p->next->next->prior=p; p->next=p->next->next; p->data.state=0; p->data.num=flag; } else p->data.state=0; } if(p->next==end)//ǰPָһһʱ {
p->data.state=0; } }//if(p->prior==block_first) else if(p->prior!=first) { if(p->next!=end) { deal1(p);
Ʒ