}
else
{
after=after->next;
before=before->next;
}
before=head;
after=head->next;
while(after!=NULL)
if(after->address==back1->size+back1->address) /*与下一块合并*/
{
back1->size=back1->size+after->size;
before->next=after->next;
free(after);
after=NULL;
}
else
{
before=before->next;
after=after->next;
}
before=head;/*将回收结点插入到合适的位置*/
after=head->next;
do{
if(after==NULL||(after->size>back1->size))
{
before->next=back1;
back1->next=after;
insert=1;
}
else
{
before=before->next;
after=after->next;
}
}while(!insert);
if(head->size<back1->size) /*修改最大块值和最大块数*/
{
head->size=back1->size;
maxblocknum++;
}
else
if(head->size==back1->size)
maxblocknum++;
}
}
void print(RECT *head) /*输出链表*/
{
RECT *before,*after;
int index,k;
before=head->next;
index=1;
if(head->next==NULL)
printf("NO part for assignment!!\n");
else
{
printf("*****index*******address********end*********size*****\n");
while(before!=NULL)
{
printf("----------------------------------------------------\n");
printf(" %-13d%-13d%-13d%-13d\n",index,before->address,before->address+before->size-1,before->size);
printf("----------------------------------------------------\n");
index++;
before=before->next;
}
}
}
/*检查回收块的合法性,back1为要回收的结点地址*/
int backcheck(RECT *head,RECT *back1)
{
RECT *before,*after;
int check=1;
if(back1->address<0||back1->size<0)
check=0;/*地址和大小不能为负*/
before=head->next;
while((before!=NULL)&&check)/*地址不能和空闲区表中结点出现重叠*/
if(((back1->address<before->address)
&&(back1->address+back1->size>before->address))
||((back1->address>=before->address)
&&(back1->address<before->address+before->size)))
check=0;
else
before=before->next;
if(check==0)
printf("Error input!!\n");
return check; /*返回检查结果*/
}