# C语言课程设计-存储管理分区分配算法

C语言课程设计-存储管理分区分配算法|c语言程序代码编程小程序设计|c语言课程设计报告课程案例/***pcb.c***/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define MAX 32767
typedef struct node   /*设置分区描述器*/
{
struct node *next;
}RECT;
/*函数原型*/
/*变量声明*/
int application1,maxblocknum;
char way;
/*主函数*/
main()
{
char choose[10];
int check;
p=malloc(sizeof(RECT));
maxblocknum=1;
p->size=MAX;
p->next=NULL;
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);/*输入申请空间大小*/
printf("Too large application!,assign fails!!\n\n");
else
}
else
if(strcmp(choose,"ac")==0) /*回收*/
{
back=malloc(sizeof(RECT));
if(check==1)
{
if(tolower(way)=='f')/*首先适应算法*/
else
}
}
}while(!strcmp(choose,"as")||!strcmp(choose,"ac"));
}
/*分配函数*/
{
RECT *after,*before,*assign;
assign=malloc(sizeof(RECT)); /*分配申请空间*/
assign->size=application;
assign->next=NULL;
else
{
while(after->size<application)/*查找适应的结点*/
{
before=before->next;
after=after->next;
}
if(after->size==application) /*结点大小等于申请大小则完全分配*/
{
maxblocknum--;
before->next=after->next;
free(after);
}
else
{
after->size=after->size-application; /*大于申请空间则截取相应大小分配*/
if(tolower(way)=='b')/*如果是最佳适应，将截取后剩余结点重新回收到合适位置*/
{
before->next=after->next;
back=after;
}
}
if(maxblocknum==0) /*修改最大数和头结点值*/
{
maxblocknum=1;
while(before!=NULL)
{
{
maxblocknum=1;
}
else
maxblocknum++;
before=before->next;
}
}
}
assign1=assign;
return assign1; /*返回分配给用户的地址*/
}
{
RECT *before,*after;
int insert;
insert=0;
while(!insert) /*将回收区插入空闲区表*/
{
if((after==NULL)||
{
before->next=back1;
back1->next=after;
insert=1;
}
else
{
before=before->next;
after=after->next;
}
}
{
before->size=before->size+back1->size;
before->next=back1->next;
free(back1);
back1=before;
}
{  /*与下一块合并*/
back1->size=back1->size+after->size;
back1->next=after->next;
free(after);
}
{
maxblocknum=1;
}
else
maxblocknum++;
}
/*最佳适应，back1为回收结点的地址*/
{
RECT *before,*after;
int insert ;
insert=0;
{
maxblocknum++;
back1->next=NULL;
}
else
{
while(after!=NULL) /*与上一块合并*/