- 2
- 0
- 约7.18千字
- 约 8页
- 2018-10-09 发布于重庆
- 举报
C语言课程设计存储管理分区分配算法II
C语言课程设计_存储管理分区分配算法
/***pcb.c***/#include stdio.h#include stdlib.h#include string.h#define MAX 32767typedef struct node? ?/*设置分区描述器*/{? ?int address,size;? ?struct node *next;}RECT;/*函数原型*/RECT *assignment(RECT *head,int application);void acceptment1(RECT *head,RECT *back1);void acceptment2(RECT *head,RECT *back1) ;int backcheck(RECT *head,RECT *back1);void print(RECT *head);/*变量声明*/RECT *head,*back,*assign1,*p;int application1,maxblocknum;char way;/*主函数*/main(){? ?char choose[10];? ?int check;? ?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(Enter the way(best or first(b/f)\n);/*选择适应策略*/? ?scanf(%c,way);? ?do{? ?? ?printf(Enter the assign or accept(as/ac)\n);? ?? ?scanf(%s,choose); /*选择分配或回收*/? ?? ?if(strcmp(choose,as)==0) /*as为分配*/? ?? ?{? ?? ?? ?printf(Input application:\n);? ?? ?? ?scanf(%d,application1);/*输入申请空间大小*/? ?? ?? ?assign1=assignment(head,application1);/*调用分配函数*/? ?? ?? ?if(assign1-address==-1)/*分配不成功*/? ?? ?? ?? ?printf(Too large application!,assign fails!!\n\n);? ?? ?? ?else? ?? ?? ?? ?printf(Success!!ADDRESS=%5d\n,assign1-address); /*分配成功*/? ?? ?? ?print(head); /*输出*/? ?? ?}? ?? ?else? ?? ?? ?if(strcmp(choose,ac)==0) /*回收*/? ?? ?? ?{? ?? ?? ?? ?back=malloc(sizeof(RECT));? ?? ?? ?? ?printf(Input Adress and Size!!\n);? ?? ?? ?? ?scanf(%d%d,back-address,back-size);/*输入回收地址和大小*/? ?? ?? ?? ?check=backcheck(head,back); /*检查*/? ?? ?? ?? ?if(check==1)? ?? ?? ?? ?{? ?? ?? ?? ?? ?if(tolower(way)==f)/*首先适应算法*/? ?? ?? ?? ?? ?? ?acceptment1(head,back); /*首先适应*/? ?? ?? ?? ?? ?else? ?? ?? ?? ?? ?? ?acceptment2(head,back);/*最佳适应*/? ?? ?? ?? ?? ?print(head);? ?? ?? ?? ?}? ?? ?? ?}? ?}while(!strcmp(choose,as)||!strcmp(choose,ac));}/*分配函数*/RECT *assignment(RECT *head,int application){? ?RECT *after,*before,*assign;? ?assign=ma
原创力文档

文档评论(0)