1 / 11
文档名称:

最佳适应算法最坏适应算法2Thebestfitalgorithmworstfitalgorithm2.doc

格式:doc   大小:27KB   页数:11页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

最佳适应算法最坏适应算法2Thebestfitalgorithmworstfitalgorithm2.doc

上传人:xiarencrh 2021/1/12 文件大小:27 KB

下载得到文件列表

最佳适应算法最坏适应算法2Thebestfitalgorithmworstfitalgorithm2.doc

文档介绍

文档介绍:最佳适应算法_最坏适应算法2(The best fit algorithm _ worst fit algorithm 2)
最佳适应算法_最坏适应算法2(The best fit algorithm _ worst fit
algorithm 2)
# includes > <
# includes > <
# includes > <
# define free 0 / / 空闲状态
# define busy 1 / / 已用状态
# define okay 1 / / 完成
# define error 0 / / 出错
# define max _ length 100 / / 最大内存空间为100m
typedef int status;
int flag; / / 标志
typedef struct freearea / / 定义一个空闲区说明表结构
{
long size; / / 分区大小
long address; / / 分区地址
int state; / / 状态
elemtype}; / / 元素类型
/ / 线性表的双向链表存储结构
typedef struct dulnode / / 结构指针
{
elemtype date;
struct dulnode * prior; / / 前趋指针
struct dulnode * next; / / 后继指针
}
dulnode, * dulinklist; / / 指针链表
dulinklist block _ first; / / 头结点
dulinklist block _ last; / / 尾结点
status alloc (int); / / 内存分配
status free (int); / / 内存回收
_ status best fit (int); / / 最佳适应算法
status _ worst fit (int); / / 最差适应算法
void show (); / / 查看分配
status initblock (); / / 开创空间表
status initblock () / / 开创带头结点的内存空间链表
{
block _ first = (dulinklist) malloc (sizeof (dulnode));
block _ last = (dulinklist) malloc (sizeof (dulnode));
block _ first - > prior = null;
block _ first - > next = block _ last;
block _ last - > prior = block _ first;
block _ last - > next = null;
block _ last - > = 0;
block _ last - > = max _ length;
block _ last - > = free;
return ok;
}
/ / 分配主存
status alloc (int ch)
{
int request = 0;
cout < < "请输入需要分配的主存大小 (单位: m)".
cin > > request;
if (request < 0 | | request = = 0)
{
cout < < "分配大小不合适, 请重试." < < endl;
return error;
}
if (n = = 1) / / 选择最佳适应算法
{
if (best _ fit (request) = = ok) cout < < "< < endl; 分配成功!"
cout "< <" 内存不足, 分配失败. "< < endl;
return ok;
}
if (n = = 2) / / 选择最差适应算法
{
if (worst _ fit (request) = = ok) cout < < "< < endl; 分配成功!"
cout "< <" 内存不足, 分配失败. "< < endl;
return ok;
}
}
/ / 最佳适应算法
_ status best fit (int request)
{
int n