- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
最佳适应算法_最坏适应算法2(The best fit algorithm _ worst fit algorithm 2)
最佳适应算法_最坏适应算法2(The best fit algorithm _ worst fit algorithm 2)
# includes stdio.h
# includes stdlib.h
# includes iostream.h
# 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 - data.address = 0;
block _ last - data.size = max _ length;
block _ last - data.state = 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; / / 记录最小剩余空间
dulinklist temp = (dulinklist) malloc (sizeof (dulnode)); / / 申请内存空间
s - data.size = request.
s - data.state = busy;
dulnode * p = block _ first - next;
dulnode * q = null; / / 记录最佳插入位置
while (p) / / 初始化最小空间和最佳位置
{
if (p - data.state = = free (p -
您可能关注的文档
- 中小企业如何做好招聘工作——做好企业的招聘工作11(How small and medium sized enterprises do a good job in recruitment -- do a good job in recruitment of enterprises 11).doc
- 中小企业物流兵法(Logistics of small and medium enterprises).doc
- 中小企业文化建设11个案例及评论(11 cases and comments on cultural construction of small and medium enterprises).doc
- 中小企业展会招商的几点经验(Some experiences of small and medium enterprises exhibition investment).doc
- 中小学特殊学生随班就读管理细则(Rules for the administration of special classes for special students in primary and secondary schools).doc
- 中小型医药保健品企业生存与发展的8大纲领(下)(8 major programs for the survival and development of small and medium sized pharmaceutical and health care enterprises (Part Two)).doc
- 中小学音乐教师业务考试理论部分复习题(Elementary and middle school music teacher business examination theory part review question).doc
- 中国的能源战略问题(China's energy strategy).doc
- 中小企业的大企业病(Big business disease of small and medium enterprises).doc
- 中文广播剧盘点(Chinese Radio Drama inventory).doc
- 曾子航三评《红楼梦》海选不是国家文物凭啥不能动(Engzi navigation three named dream of Red Mansions audition not by what the state cultural relics can not move).doc
- 曹邺诗集(Cao Ye Poetry).doc
- 最全面的空压机安装维护手册22047(The most comprehensive air compressor installation and maintenance manual 22047).doc
- 最全反转剧(Most complete reversal drama).doc
- 最受欢迎的20种水果(20 most popular fruits).doc
- 曾被誉为中国十大经典广告的策划案例!!!!(Has been hailed as China's ten classic advertising planning case!!!!).doc
- 最常用命令(Most commonly used commands).doc
- 最强最新生活小常识100招(The most powerful, the latest life, 100 Tips).doc
- 最新2008年入党思想汇报(The latest ideological report on joining the party in 2008).doc
- 最全面的空压机安装维护手册22400(The most comprehensive air compressor installation and maintenance manual 22400).doc
最近下载
- 基坑支护内支撑梁拆除施工方案.docx VIP
- 最新人教版一年级上册《数学游戏》课件(整套)教学PPT(2024年秋-新教材).pptx VIP
- 最新人教版一年级数学上册《数学游戏》教学课件(整套)PPT(2024秋-新教材).pptx VIP
- GBT6058-2005 纤维缠绕压力容器制备和内压试验方法.pdf
- GB╱T 23711.1-2009 氟塑料衬里压力容器电火花试验方法.pdf
- 7m焦炉推焦车的结构特征.pdf
- 研发领料单模板.docx VIP
- 辽宁省技工学校审批表.doc VIP
- GB 26501--2011 氟塑料衬里压力容器 通用技术条件.pdf
- 施工放样报验单.doc VIP
文档评论(0)