java成组链接法的实现_c++磁盘存储空间的管理模拟(UNIX存储管理的成组链接法的设计与实现)...

[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<

}

}

}

694748ed64b9390909c0d88230893790.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值