//动态分区分配算法 (首次适应算法) 与(最佳适应算法)和其回收过程
#include <iostream>
#include<stdlib.h>
using namespace std;
#define FREE 0
#define BUSY 1
#define MAX_length 640
typedef struct freeArea//首先定义空闲区分表结构
{
int flag;
int size;
int ID;
int address;
}Elemtype;
typedef struct Free_Node
{
Elemtype date;
struct Free_Node *front;
struct Free_Node *next;
}Free_Node,*FNodeList;
FNodeList block_first;
FNodeList block_last;
int alloc(int tag);//内存分配
int free(int ID);//内存回收
int first_fit(int ID,int size);//首次适应算法
int best_fit(int ID,int size);//最佳适应算法
void show();//查看分配
void init();//初始化
void Destroy(Free_Node *p);//销毁节点
void menu();
void init()//
{
block_first=new Free_Node;
block_last = new Free_Node;
block_first->front=NULL;
block_first->next=block_last;
block_last->front=block_first;
block_last->next=NULL;
block_last->date.address=0;
block_last->date.flag=FREE;
block_last->date.ID=FREE;
block_last->date.size=MAX_length;
}
//实现内存分配
int alloc(int tag)
{
int ID,size1;
cout<<"请输入作业号:";
cin>>ID;
cout<<"请输入所需内存大小:";
cin>>size1;
if (ID<=0 || size1<=0)
{
cout<<"输入错误!请输入
动态分区分配算法(四种)
于 2022-11-25 13:31:31 首次发布