資源簡介
操作系統的課程設計,有最先適應法,最優適應法和最差適應法。覺得好的就給個評價,謝謝

代碼片段和文件信息
#include??
#include?
using?namespace?std;?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
#include“stdlib.h“
typedef?struct?area{
????int?start;
????int?length;
????int?state;
????struct?area?*next;
}Area*pArea;
const?int?Max=255;
void?PrintMemoryState(Area?*);
void?FirstFit(Area?*);
void?BestFit(Area?*);
void?WorstFit(Area?*);
void?MaxLength(Area?*);
int?main()
{
????Area?*work;
????Area?*p;
Area?*p1;
Area?*p2;
Area?*p3;Area?*p4;Area?*p5;
????int?Choice;
????//int?start;
????pArea?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=1;
????head->next=NULL;
????//裝入系統
????printf(“.............正在載入系統中..............\n“);
????work->start=0;
work->length=1;
work->next=NULL;
work->state=1;
????head->next=work;
????p=(Area?*)malloc(sizeof(Area));
????p->start=1;
p->length=32;
// p->next=NULL;
p->state=-1;
????work->next=p;
p1=(Area?*)malloc(sizeof(Area));
????p1->start=33;
p1->length=16;
// p1->next=NULL;
p1->state=-1;
????p->next=p1;
p2=(Area?*)malloc(sizeof(Area));
????p2->start=49;
p2->length=8;
// p2->next=NULL;
p2->state=-1;
????p1->next=p2;
p3=(Area?*)malloc(sizeof(Area));
????p3->start=57;
p3->length=4;
//p3->next=NULL;
p3->state=-1;
????p2->next=p3;
????p4=(Area?*)malloc(sizeof(Area));
????p4->start=61;
p4->length=64;
// p4->next=NULL;
p4->state=-1;
????p3->next=p4;
????p5=(Area?*)malloc(sizeof(Area));
????p5->start=125;
p5->length=Max-125;
p5->next=NULL;
p5->state=-1;
????p4->next=p5;
????PrintMemoryState(head);//輸出當前的內存使用狀況
????//開始循環
????while(1)
????{
????????printf(“?1.最先適應法;2.最優適應法;3.最差適應法;0.退出程序\n“);
????????printf(“?#“);
????????scanf(“%d“&Choice);//輸入你所要的選項。為choice?的值
????????switch(Choice)
????????{
????????????case?0:
????????????????printf(“The?System?Is?Shutdown...?\n“);
????????????????goto?A;
????????????case?1:
????????????????FirstFit(head);
????????????????PrintMemoryState(head);//最先適應法
????????????????continue;
case?2:
????????????????BestFit(head);
????????????????PrintMemoryState(head);//最優適應法
????????????????continue;
????????????case?3:
????????????????WorstFit(head);
PrintMemoryState(head);//最差適應法
????????????????continue;??????????????
????????????default:
????????????????printf(“Please?input?a?right?number!\n“);
????????????????break;
????????}
????}
A:????return?0;
}
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/*->length+temp->start)*/!=NULL);
????printf(“\t%8d\t%8d\t%8d\n
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????82944??2008-06-27?17:56??操作系統4\Debug\vc60.idb
?????文件?????118784??2008-06-27?11:41??操作系統4\Debug\vc60.pdb
?????文件?????254415??2008-06-27?17:56??操作系統4\Debug\周峰.obj
?????文件?????561225??2008-06-27?17:56??操作系統4\Debug\操作系統4.exe
?????文件?????795196??2008-06-27?17:56??操作系統4\Debug\操作系統4.ilk
?????文件????1999684??2008-06-26?14:01??操作系統4\Debug\操作系統4.pch
?????文件????1106944??2008-06-27?11:41??操作系統4\Debug\操作系統4.pdb
?????文件???????7751??2008-06-27?11:41??操作系統4\周峰.cpp
?????文件???????4317??2008-06-25?21:44??操作系統4\操作系統4.dsp
?????文件????????526??2008-06-25?20:10??操作系統4\操作系統4.dsw
?????文件??????41984??2008-06-27?17:56??操作系統4\操作系統4.ncb
?????文件??????48640??2008-06-27?17:56??操作系統4\操作系統4.opt
?????文件????????895??2008-06-27?17:56??操作系統4\操作系統4.plg
?????目錄??????????0??2008-06-27?11:41??操作系統4\Debug
?????目錄??????????0??2008-06-27?17:56??操作系統4
-----------?---------??----------?-----??----
??????????????5023305????????????????????15
- 上一篇:音樂樂譜提取軟件.rar
- 下一篇:口罩佩戴識別數據集共5份
評論
共有 條評論