预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

C语言课程设计_存储管理分区分配算法/***pcb.c***/#include"stdio.h"#include"stdlib.h"#include"string.h"#defineMAX32767typedefstructnode/*设置分区描述器*/{intaddress,size;structnode*next;}RECT;/*函数原型*/RECT*assignment(RECT*head,intapplication);voidacceptment1(RECT*head,RECT*back1);voidacceptment2(RECT*head,RECT*back1);intbackcheck(RECT*head,RECT*back1);voidprint(RECT*head);/*变量声明*/RECT*head,*back,*assign1,*p;intapplication1,maxblocknum;charway;/*主函数*/main(){charchoose[10];intcheck;head=malloc(sizeof(RECT));/*建立可利用区表的初始状态*/p=malloc(sizeof(RECT));head->size=MAX;head->address=0;head->next=p;maxblocknum=1;p->size=MAX;p->address=0;p->next=NULL;print(head);/*输出可利用表初始状态*/printf("Entertheway(bestorfirst(b/f)\n");/*选择适应策略*/scanf("%c",&way);do{printf("Entertheassignoraccept(as/ac)\n");scanf("%s",choose);/*选择分配或回收*/if(strcmp(choose,"as")==0)/*as为分配*/{printf("Inputapplication:\n");scanf("%d",&application1);/*输入申请空间大小*/assign1=assignment(head,application1);/*调用分配函数*/if(assign1->address==-1)/*分配不成功*/printf("Toolargeapplication!,assignfails!!\n\n");elseprintf("Success!!ADDRESS=%5d\n",assign1->address);/*分配成功*/print(head);/*输出*/}elseif(strcmp(choose,"ac")==0)/*回收*/{back=malloc(sizeof(RECT));printf("InputAdressandSize!!\n");scanf("%d%d",&back->address,&back->size);/*输入回收地址和大小*/check=backcheck(head,back);/*检查*/if(check==1){if(tolower(way)=='f')/*首先适应算法*/acceptment1(head,back);/*首先适应*/elseacceptment2(head,back);/*最佳适应*/print(head);}}}while(!strcmp(choose,"as")||!strcmp(choose,"ac"));}/*分配函数*/RECT*assignment(RECT*head,intapplication){RECT*after,*before,*assign;assign=malloc(sizeof(RECT));/*分配申请空间*/assign->size=application;assign->next=NULL;if(application>head->size||application<=0)assign->address=-1;/*申请无效*/else{before=head;after=head->next;while(after->size<application)/*查找适应的结点*/{before=before->next;after=after->next;}if(after->size==application)/*结点大小等于申请大小则完全分配*/{if(after->size==head->size)maxblocknum--;before->next=after->next;assign->address=after->address;free(after);}else{if(after->size==head->size)maxbl