-
大小: 1.69MB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2023-10-23
- 語言: 其他
- 標(biāo)簽: 動態(tài)分區(qū)??
資源簡介
循環(huán)首次適應(yīng)算法
最佳適應(yīng)算法
最壞適應(yīng)算法

代碼片段和文件信息
#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;
????//開始循環(huán)
????while(1)
????{
system(“cls“);
init();
PrintMemoryState(head);
????????printf(“1.最優(yōu)適應(yīng)法;2.最差適應(yīng)法;0.退出程序\n“);
????????scanf(“%d“&Choice);//輸入你所要的選項(xiàng)。為choice?的值
????????switch(Choice)
????????{
????????????case?0:
????????????????printf(“The?System?Is?Shutdown...?\n“);
????????????????exit(0);
case?1:
????????????????BestFit(head);
????????????????PrintMemoryState(head);//最優(yōu)適應(yīng)法
break;
case?2:
????????????????WorstFit(head);
PrintMemoryState(head);//最差適應(yīng)法
????????????????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字節(jié)的內(nèi)存塊
????work=(Area?*)malloc(sizeof(Area));
????head->start=0;
????head->length=0;
????head->state=0;
????head->next=NULL;
????//裝入系統(tǒng)
????printf(“.............正在載入系統(tǒng)中..............\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內(nèi)存長度\t內(nèi)存狀態(tài)\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)//裝入作業(yè)最差適應(yīng)法
{
????int?lengthtemp;
int?a[3];
????Area?*last=NULL;
????Area?*newFree=NULL;
int?i;
int?name=0;
cout<<“請分別輸入需要分配內(nèi)存的3個作業(yè)內(nèi)存長度:“< for(i=1;i<=3;i++)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2008-06-27?17:56??最優(yōu)最差算法\
?????目錄???????????0??2008-06-27?11:41??最優(yōu)最差算法\Debug\
?????文件????????7580??2010-01-27?18:36??最優(yōu)最差算法\Debug\BuildLog.htm
?????文件??????400588??2010-01-27?18:36??最優(yōu)最差算法\Debug\dynamic.obj
?????文件??????????67??2010-01-27?18:36??最優(yōu)最差算法\Debug\mt.dep
?????文件???????82944??2008-06-27?17:56??最優(yōu)最差算法\Debug\vc60.idb
?????文件??????118784??2008-06-27?11:41??最優(yōu)最差算法\Debug\vc60.pdb
?????文件??????478208??2010-01-27?18:36??最優(yōu)最差算法\Debug\vc90.idb
?????文件??????184320??2010-01-27?18:36??最優(yōu)最差算法\Debug\vc90.pdb
?????文件??????399437??2010-01-27?14:34??最優(yōu)最差算法\Debug\余子晨.obj
?????文件??????500736??2010-01-27?18:36??最優(yōu)最差算法\Debug\操作系統(tǒng)4.exe
?????文件?????????406??2010-01-27?14:29??最優(yōu)最差算法\Debug\操作系統(tǒng)4.exe.em
?????文件?????????472??2010-01-27?14:29??最優(yōu)最差算法\Debug\操作系統(tǒng)4.exe.em
?????文件?????????381??2010-01-27?18:36??最優(yōu)最差算法\Debug\操作系統(tǒng)4.exe.intermediate.manifest
?????文件??????795196??2010-01-27?18:36??最優(yōu)最差算法\Debug\操作系統(tǒng)4.ilk
?????文件?????2706432??2010-01-27?18:36??最優(yōu)最差算法\Debug\操作系統(tǒng)4.pdb
?????文件????????5686??2010-01-27?17:31??最優(yōu)最差算法\dynamic.cpp
?????文件????????4317??2008-06-25?21:44??最優(yōu)最差算法\操作系統(tǒng)4.dsp
?????文件?????????526??2008-06-25?20:10??最優(yōu)最差算法\操作系統(tǒng)4.dsw
?????文件?????1567744??2010-01-27?20:09??最優(yōu)最差算法\操作系統(tǒng)4.ncb
?????文件???????48640??2008-06-27?17:56??最優(yōu)最差算法\操作系統(tǒng)4.opt
?????文件?????????895??2008-06-27?17:56??最優(yōu)最差算法\操作系統(tǒng)4.plg
?????文件?????????891??2010-01-27?20:09??最優(yōu)最差算法\操作系統(tǒng)4.sln
?????文件???????14848??2010-01-27?20:09??最優(yōu)最差算法\操作系統(tǒng)4.suo
?????文件????????5201??2010-01-27?21:32??最優(yōu)最差算法\操作系統(tǒng)4.vcproj
?????文件????????1427??2010-01-27?20:09??最優(yōu)最差算法\操作系統(tǒng)4.vcproj.PC-201001031646.Administrator.user
?????文件????????1427??2010-01-26?23:48??最優(yōu)最差算法\操作系統(tǒng)4.vcproj.PC-201001092322.Administrator.user
?????文件????????1427??2010-01-27?22:53??最優(yōu)最差算法\操作系統(tǒng)4.vcproj.XSIT-4F51DE9CAE.xsit.user
評論
共有 條評論