[c++]代码库#include
#include
#include
const int MAXGROUP=10;//定义组的大小
const int MAXJOB=100;//定义一个作业最大能申请的块数
//结构体定义
typedef struct node
{
int quantity;
int cell[MAXGROUP];
struct node *next;
} group;
typedef struct node1
{
char name[20];
int quantity;
int cell[MAXJOB];
struct node1 *next;
} job;
group *head;
int total;
job *jhead;
//初始化组函数
group *initial()
{
int i;
group *p;
p=new group;
p->quantity=0;
p->next=NULL;
for ( i=0; i
{
p->cell[i]=-1;
}
return p;
}
//初始化作业函数
job *initial_job()
{
int i;
job *p;
p=new job;
strcpy ( p->name,"" );
p->quantity=0;
p->next=NULL;
for ( i=0; i
{
p->cell[i]=-1;
}
return p;
}
//读入空闲块流文件
void readData()
{
FILE *fp;
char fname[20];
int temp;
group *p;
cout<
cin>>fname;
if ( ( fp=fopen ( "5unix.txt","r" ) ) ==NULL )
{
cout<
}
else
{
cout<
cout<
while ( !feof ( fp ) )
{
fscanf ( fp,"%d ",&temp );
if ( head->quantity
{
head->cell[head->quantity]=temp;
head->quantity++;
}
else
{
p=initial();
p->next=head;
head=p;
p->cell[p->quantity]=temp;
p->quantity++;
}
total++;
//输出初始数据
cout<
}
cout<
}
}
//查看专用块函数
void view()
{
int i;
cout<
cout<
cout<
for ( i=0; iquantity; i++ )
{
cout<cell[i]<
}
cout<quantity;
cout<
}
//新申请函数
void bid()
{
char jobname[20];
int number;
int i;
job *p;
cout<
cout<
cin>>jobname;
cout<
cin>>number;
if ( number>total )
{
cout<
}
else
{
p=initial_job();
strcpy ( p->name,jobname );
p->next=jhead->next;
jhead->next=p;
p->quantity=number;
cout<
for ( i=0; i
{
if ( head->quantity>1 )
{
cout<cell[head->quantity-1]<
head->quantity--;
p->cell[i]=head->cell[head->quantity-1];
}
else
{
cout<cell[0]<
p->cell[i]=head->cell[head->quantity-1];
head->quantity--;
if ( head->next!=NULL )
{
head=head->next;
}
}
total--;
}
}
cout<
}
//撤消作业
void finish()
{
char jobname[20];
int i;
job *p,*q;
group *r;
cout<
cin>>jobname;
q=jhead;
p=jhead->next;
while ( ( p!=NULL ) && ( strcmp ( p->name,jobname ) ) )
{
q=q->next;
p=p->next;
}
if ( p==NULL )
{
cout<
}
else
{
for ( i=0; iquantity; i++ )
{
if ( head->quantity
{
head->cell[head->quantity]=p->cell[i];
head->quantity++;
}
else
{
r=initial();
r->next=head;
head=r;
r->cell[r->quantity]=p->cell[i];
r->quantity++;
}
}
total+=p->quantity;
q->next=p->next;
delete p;
}
}
//显示版权信息函数
void version()
{
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
}
void main()
{
int f=1;
int chioce;
version();
head=initial();
total=0;
jhead=initial_job();
readData();
while ( f==1 )
{
cout<
cout<
cout<
cout<
cout<
cin>>chioce;
switch ( chioce )
{
case 1:
bid();
break;
case 2:
finish();
break;
case 3:
view();
break;
case 0:
f=0;
break;
default:
cout<
}
}
}