欢迎来到天天文库
浏览记录
ID:58460393
大小:49.00 KB
页数:14页
时间:2020-09-03
《广工 操作系统课程设计 最佳适应算法、最坏适应算法、循环首次适应算法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、动态分区分配算法仿真,循环首次适应算法、最佳适应算法、最坏适应算法#include#include//在输入输出流中用到控制符#include//用到了SetConsoleTextAttribute函数#defineminsize2//事先规定的不再切割的剩余分区大小为2usingnamespacestd;structNode{intname;intstart;intsize;intstate;Node*pre;Node*next;};typedefstructDlinklist{Node*head;}Dlist;//====
2、===============Dlistpro,fre;intmemory,name,size,fit;Node*temp=NULL;//temp是NestFit算法中的起始查寻指针//===================voidinitDlist(Dlist&L)//创建带有头结点的双向链表{L.head=newNode;L.head->next=L.head->pre=NULL;}voidMemoryInit()//初始化两个链表{initDlist(pro);//process链表initDlist(fre);//freeblock链表Node*p=newNode;p->nam
3、e=0;p->start=0;p->state=0;p->size=memory;p->next=NULL;//这里曾错写成p->pre..............p->pre=fre.head;//这里曾漏写fre.head->next=p;}intgetLength(Dlist&L)//返回链表的长度,即元素的个数{intm=0;Node*p=L.head->next;while(p!=NULL){m++;p=p->next;}returnm;}voidarrangeSmaller(Dlist&L)//冒泡排序,链表按size进行排序,从小到大{intlength=getLengt
4、h(L);for(inti=0;i=2的时候才排序{Node*p=L.head->next;Node*q=p->next;inta,b,c,d;//==========================================================================for(intj=0;jsize>q->size)//交换位置,如果前面的大于后面的,使小的上浮,如果两个相等,则还是原来在前的保持在前{a=p->size;p->size=q->size;q->s
5、ize=a;b=p->name;p->name=q->name;q->name=b;c=p->start;p->start=q->start;q->start=c;d=p->state;//==========================================================================p->state=q->state;q->state=d;}p=p->next;q=p->next;}}}voidarrangeBigger(Dlist&L)//链表按size进行排序,从大到小{intlength=getLength(L);for(in
6、ti=0;inext;Node*q=p->next;inta,b,c,d;for(intj=0;jsizesize){a=p->size;p->size=q->size;q->size=a;b=p->name;p->name=q->name;q->name=b;c=p->start;p->start=q->start;q->start=c;d=p->state;//=======================================================
7、===================p->state=q->state;q->state=d;}p=p->next;q=p->next;}}}voidarrangeStart(Dlist&L)//链表按start递增排序{intlength=getLength(L);for(inti=0;inext;Node*q=p->next;inta,b,c,d;for(intj=0;j
此文档下载收益归作者所有