}
/************************************** 申请空间操作
***************************************/ work *request(work *w,int WST[256]){
int i,m,n,flag=0;
free_link *p,*r,*e;//r->free_number 用于查找空闲区的块数
office *q,*s,*t,*u;//s 创建新节点,存储新建文件的信息,n用于查找是否有
重复节点
p=w->p; r=p; q=w->q; t=q; u=q->next;
printf(\请输入文件名和块数:\s=(office*)malloc(sizeof(office)); s->next=NULL; while(t->next!=NULL)
t=t->next;
scanf(\while(u!=NULL){
if(strcmp(s->office,u->office)==0){ }
flag=1;
printf(\对不起,该文件已存在!\\n\free(s); break;
u=u->next; }
if(flag==0){
13
while(r!=NULL){
if((r->free_number)>=(s->office_number))//用于查找空闲区中空闲
块数是否大于欲分配的块数
}
if(r==NULL){ } else{
t->next=s;
m=r->start_location;//空闲区的起始地址
s->begin_location=r->start_location;//作业从空闲区的起始地址开printf(\对不起,没有足够的空间分配失败!\\n\free(s);
break;
r=r->next;
始分配
r->start_location=r->start_location+s->office_number;//改变空
闲区空闲块数的起始地址
r->free_number=r->free_number-s->office_number;//改变空间区块
数的大小
n=(r->start_location-1);//新的空间区的起始地址-1 for(i=m;i<=n;i++)//模拟分配
WST[i]=1;
if(r->free_number==0){
if(p==r){//p==r说明内存中只有一个整块的空闲区 } else{
e=p;
while(e!=NULL){
14
free(r); p=NULL;
}
}
}
}
}
}
if(e->next==r)
break;
e=e->next;
e->next=r->next; free(r);
w->p=p; w->q=q; return w;
/********************************************* 回收空间操作
**********************************************/ work *delect(work *w,int WET[]){
char name[20]; int i;
free_link *p,*r,*t; office *q,*s,*e; p=w->p; r=p; t=p; q=w->q; s=q; e=q; s=s->next; if(s==NULL){
15
}
printf(\没有可以回收的文件!\\n\
else {
printf(\请输入文件名:\cin>>name; while(s!=NULL){ }
if(s==NULL){ } else{
cout<<\对不起没有找到相关文件!\\n\if(strcmp(s->office,name)==0)
break;
s=s->next;
if((WST[s->begin_location-1]==0&&WST[s->begin_location+s->office_numb
er]==1&&s->begin_location-1>=0)
||(WST[s->begin_location-1]==0&&s->begin_location+s->office_number==2
56&&s->begin_location-1>=0)){
while(r!=NULL){
if((r->start_location+r->free_number)==s->begin_location)
}
}
r->free_number=r->free_number+s->office_number;
break;
r=r->next;
if((WST[s->begin_location-1]==1&&WST[s->begin_location+s->office_numb
er]==0&&
s->begin_location+s->office_number<256)||(s->begin_location==0&&
WST[s->begin_location+s->office_number]==0&&s->begin_location+s->offi
16
ce_number<256)){
while(r!=NULL){
if((s->begin_location+s->office_number)==r->start_location)
}
r->start_location=r->start_location-s->office_number; r->free_number=r->free_number+s->office_number;
break;
r=r->next;
}if(WST[s->begin_location-1]==0&&WST[s->begin_location+s->office_numb
er]==0&&s->begin_location-1>=0&&s->begin_location+s->office_number<256){
while(r!=NULL){
if((s->begin_location+s->office_number)==r->start_location){
}
}
r=r->next;
t=r; break;
r->free_number=r->free_number+s->office_number+t->free_number;
}
free(t);
if((WST[s->begin_location-1]==1&&WST[s->begin_location+s->office_numb
er]==1&&s->begin_location-1>=0
&&s->begin_location+s->office_number<256)
||(s->begin_location==0&&WST[s->begin_location+s->office_number]==1&& s->begin_location+s->office_number<256)
||(WST[s->begin_location-1]==1&&s->begin_location+s->office_number==2
56&&s->begin_location-1>=0)
||(s->begin_location==0&&s->begin_location+s->office_number==256)){
t=(free_link*)malloc(sizeof(free_link)); t->next=NULL;
17