資源簡介
循環首次適應算法
最佳適應算法
最壞適應算法

代碼片段和文件信息
#include??
#include?
using?namespace?std;?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
#include“stdlib.h“
typedef?struct?area{
????int?start;
????int?length;
????int?state;
????struct?area?*next;
}Area*pArea;
Area?*head;
const?int?Max=255;
void?PrintMemoryState(Area?*);
void?BestFit(Area?*);
void?WorstFit(Area?*);
void?init();
void??main()
{
????int?Choice;
????//開始循環
????while(1)
????{
system(“cls“);
init();
PrintMemoryState(head);
????????printf(“1.最優適應法;2.最差適應法;0.退出程序\n“);
????????scanf(“%d“&Choice);//輸入你所要的選項。為choice?的值
????????switch(Choice)
????????{
????????????case?0:
????????????????printf(“The?System?Is?Shutdown...?\n“);
????????????????exit(0);
case?1:
????????????????BestFit(head);
????????????????PrintMemoryState(head);//最優適應法
break;
case?2:
????????????????WorstFit(head);
PrintMemoryState(head);//最差適應法
????????????????break;??????????????
????????????default:
????????????????printf(“Please?input?a?right?number!\n“);
????????????????break;
????????}
system(“pause“);
????}
}
void?init()
{
????Area?*work;
????Area?*p;
Area?*p1;
Area?*p2;
Area?*p3;Area?*p4;Area?*p5;
????//int?start;
delete?head;
????head=(Area?*)malloc(sizeof(Area));//分配頭指針
//extern?void?*malloc(unsigned?int?num_bytes)功能:分配長度為num_bytes字節的內存塊
????work=(Area?*)malloc(sizeof(Area));
????head->start=0;
????head->length=0;
????head->state=0;
????head->next=NULL;
????//裝入系統
????printf(“.............正在載入系統中..............\n“);
????work->start=0;
work->length=1;
work->next=NULL;
work->state=0;
????head->next=work;
????p=(Area?*)malloc(sizeof(Area));
????p->start=1;
p->length=32;
// p->next=NULL;
p->state=0;
????work->next=p;
p1=(Area?*)malloc(sizeof(Area));
????p1->start=33;
p1->length=16;
// p1->next=NULL;
p1->state=0;
????p->next=p1;
p2=(Area?*)malloc(sizeof(Area));
????p2->start=49;
p2->length=8;
// p2->next=NULL;
p2->state=0;
????p1->next=p2;
p3=(Area?*)malloc(sizeof(Area));
????p3->start=57;
p3->length=4;
//p3->next=NULL;
p3->state=0;
????p2->next=p3;
????p4=(Area?*)malloc(sizeof(Area));
????p4->start=61;
p4->length=64;
// p4->next=NULL;
p4->state=0;
????p3->next=p4;
????p5=(Area?*)malloc(sizeof(Area));
????p5->start=125;
p5->length=Max-125;
p5->next=NULL;
p5->state=0;
????p4->next=p5;
}
void?PrintMemoryState(Area?*head)
{
????int?state=-1;
????Area?*temp=(Area?*)malloc(sizeof(Area));
????temp=head->next;
????printf(“\t起始地址\t內存長度\t內存狀態\n“);
do
????{
????????printf(“\t%8d\t%8d\t%8d\n“temp->starttemp->lengthtemp->state);
????????temp=temp->next;
????}while(temp!=NULL);
????return?;
}
void?WorstFit(Area?*head)//裝入作業最差適應法
{
????int?lengthtemp;
int?a[3];
????Area?*last=NULL;
????Area?*newFree=NULL;
int?i;
int?name=0;
cout<<“請分別輸入需要分配內存的3個作業內存長度:“< for(i=1;i<=3;i++)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2008-06-27?17:56??最優最差算法\
?????目錄???????????0??2008-06-27?11:41??最優最差算法\Debug\
?????文件????????7580??2010-01-27?18:36??最優最差算法\Debug\BuildLog.htm
?????文件??????400588??2010-01-27?18:36??最優最差算法\Debug\dynamic.obj
?????文件??????????67??2010-01-27?18:36??最優最差算法\Debug\mt.dep
?????文件???????82944??2008-06-27?17:56??最優最差算法\Debug\vc60.idb
?????文件??????118784??2008-06-27?11:41??最優最差算法\Debug\vc60.pdb
?????文件??????478208??2010-01-27?18:36??最優最差算法\Debug\vc90.idb
?????文件??????184320??2010-01-27?18:36??最優最差算法\Debug\vc90.pdb
?????文件??????399437??2010-01-27?14:34??最優最差算法\Debug\余子晨.obj
?????文件??????500736??2010-01-27?18:36??最優最差算法\Debug\操作系統4.exe
?????文件?????????406??2010-01-27?14:29??最優最差算法\Debug\操作系統4.exe.em
?????文件?????????472??2010-01-27?14:29??最優最差算法\Debug\操作系統4.exe.em
?????文件?????????381??2010-01-27?18:36??最優最差算法\Debug\操作系統4.exe.intermediate.manifest
?????文件??????795196??2010-01-27?18:36??最優最差算法\Debug\操作系統4.ilk
?????文件?????2706432??2010-01-27?18:36??最優最差算法\Debug\操作系統4.pdb
?????文件????????5686??2010-01-27?17:31??最優最差算法\dynamic.cpp
?????文件????????4317??2008-06-25?21:44??最優最差算法\操作系統4.dsp
?????文件?????????526??2008-06-25?20:10??最優最差算法\操作系統4.dsw
?????文件?????1567744??2010-01-27?20:09??最優最差算法\操作系統4.ncb
?????文件???????48640??2008-06-27?17:56??最優最差算法\操作系統4.opt
?????文件?????????895??2008-06-27?17:56??最優最差算法\操作系統4.plg
?????文件?????????891??2010-01-27?20:09??最優最差算法\操作系統4.sln
?????文件???????14848??2010-01-27?20:09??最優最差算法\操作系統4.suo
?????文件????????5201??2010-01-27?21:32??最優最差算法\操作系統4.vcproj
?????文件????????1427??2010-01-27?20:09??最優最差算法\操作系統4.vcproj.PC-201001031646.Administrator.user
?????文件????????1427??2010-01-26?23:48??最優最差算法\操作系統4.vcproj.PC-201001092322.Administrator.user
?????文件????????1427??2010-01-27?22:53??最優最差算法\操作系統4.vcproj.XSIT-4F51DE9CAE.xsit.user
評論
共有 條評論