資源簡介
操作系統最先適應算法代碼,使用節點實現,進行內存的分配與回收,還可以查看鏈表

代碼片段和文件信息
#include?
using?namespace?std;
struct?node
{
int?size;
int?beginning;
int?name;
bool?free;
node?*next;
};
void?allocation(node?*head);
void?recycle(node?*head);
void?examine(node?*head);
int?main()
{
bool?a?=?true;
node?*head?=?new?node;
head->next?=?NULL;
node?*p?=?new?node;
p->next?=?head->next;
head->next?=?p;
p->size?=?1024;
p->beginning?=?0;
p->free?=?true;
p->name?=?1024;
while(a)
{
????cout<<“******最先適應算法******“< ????cout<<“1.分配內存???2.回收內存“< ????cout<<“3.查看分配???4.退出“< cout<<“************************“< ????int?choose;
????cin>>choose;
switch(choose)
{
case?1:allocation(head);
???break;
case?2:recycle(head);
???break;
case?3:examine(head);
???break;
case?4:
??cout<<“退出分配!“< ??a=false;
??break;
default:
?cout<<“輸入錯誤!請重新輸入“< }
}
}
void?allocation(node?*head)
{
?cout<<“******分配內存******“< ?cout<<“請輸入分配的進程個數“< ?int?number;
?cin>>number;
?int?size;
?int?name;
?for(int?i?=?0;i ?{
?cout<<“請輸入進程的大小“< ?cin>>size;?
?cout<<“請輸入進程的名字“< ?cin>>name;
???node?*p;
???for(p?=?head->next;p!=NULL;p=p->next)
???{
???if(p->free?==?true?&&?p->size>size)
???{
???node?*s?=?new?node;
???s->next?=?p->next;
???p->next?=s;
???s->size?=p->size-size;
???s->name?=?p->name;
???s->beginning?=?p->beginning+size;
???s->free?=?true;
???p->size?=?size;
???p->free?=?false;
???p->name?=?name;
????cout<<“第“< cout<<“****************************“< break;
???}
???else?if(p->free?==?true?&&?p->size?==?size)
???{
???p->free?=?false;
???p->name?=?name;
????cout<<“第“< cout<<“****************************“< break;
???}
???else?if(p->next?==?NULL?&&?p->size ???{
???cout<<“第“< ???cout<<“****************************“< ???}
???else
???{
???continue;
???}
???}
?}
}
void?recycle(node?*head)
{
cout<<“請輸入回收的內存編號“< int?recyclename;
cin>>recyclename;
node?*p*q;
p=q=head;
for(p=p->next;p!=NULL;q=pp=p->next)
{
if(p->name?==?recyclename)
{
p->free?=?true;
cout<name< cout<free<
if(q->free?==?true)
{
q->size?=?q->size?+?p->size;
q->next?=?p->next;
p=q;
}
if(p->next->free?==?true)
{
p->size?=?p->size?+?p->next->size;
p->next?=?p->next->next;
}
cout<<“釋放內存成功“< break;
}
else?if(p->next?==?NULL?&&?p->name?!=?recyclename?)
{
cout<<“釋放內存失敗“< break;
}
else
{
continue;
}
}
}
void?examine(node?*head)
{
node?*p;
p?=?head->next;
while(p?!=NULL)
{
cout<<“****************************“< cout<<“進程名字:“<name< cout<<“開始位置:“<beginning<
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-20?21:30??操作系統3\
?????目錄???????????0??2018-11-20?21:19??操作系統3\Debug\
?????文件???????40960??2018-11-20?21:19??操作系統3\Debug\操作系統3.exe
?????文件??????379856??2018-11-20?21:19??操作系統3\Debug\操作系統3.ilk
?????文件??????560128??2018-11-20?21:19??操作系統3\Debug\操作系統3.pdb
?????目錄???????????0??2018-11-20?21:16??操作系統3\ipch\
?????目錄???????????0??2018-11-20?21:16??操作系統3\ipch\操作系統3-fcfd94c5\
?????文件????14352384??2018-11-20?21:16??操作系統3\ipch\操作系統3-fcfd94c5\操作系統3-c6c18782.ipch
?????目錄???????????0??2018-11-19?20:25??操作系統3\操作系統3\
?????目錄???????????0??2018-11-20?21:19??操作系統3\操作系統3\Debug\
?????文件????????9590??2018-11-20?21:19??操作系統3\操作系統3\Debug\CL.read.1.tlog
?????文件?????????282??2018-11-20?21:19??操作系統3\操作系統3\Debug\CL.write.1.tlog
?????文件?????????552??2018-11-20?21:19??操作系統3\操作系統3\Debug\cl.command.1.tlog
?????文件????????1106??2018-11-20?21:19??操作系統3\操作系統3\Debug\li
?????文件????????2768??2018-11-20?21:19??操作系統3\操作系統3\Debug\li
?????文件?????????500??2018-11-20?21:19??操作系統3\操作系統3\Debug\li
?????文件?????????408??2018-11-20?21:19??操作系統3\操作系統3\Debug\mt.command.1.tlog
?????文件?????????690??2018-11-20?21:19??操作系統3\操作系統3\Debug\mt.read.1.tlog
?????文件?????????232??2018-11-20?21:19??操作系統3\操作系統3\Debug\mt.write.1.tlog
?????文件??????216064??2018-11-20?21:19??操作系統3\操作系統3\Debug\vc100.idb
?????文件??????241664??2018-11-20?21:19??操作系統3\操作系統3\Debug\vc100.pdb
?????文件?????????381??2018-11-20?21:19??操作系統3\操作系統3\Debug\操作系統3.exe.intermediate.manifest
?????文件??????????61??2018-11-20?21:19??操作系統3\操作系統3\Debug\操作系統3.lastbuildstate
?????文件????????2159??2018-11-20?21:19??操作系統3\操作系統3\Debug\操作系統3.log
?????文件?????????713??2018-11-19?20:25??操作系統3\操作系統3\Debug\操作系統3.vcxprojResolveAssemblyReference.cache
?????文件???????????0??2018-11-19?20:25??操作系統3\操作系統3\Debug\操作系統3.write.1.tlog
?????文件???????58830??2018-11-20?21:19??操作系統3\操作系統3\Debug\最先算法.obj
?????文件????????3231??2018-11-19?20:25??操作系統3\操作系統3\操作系統3.vcxproj
?????文件?????????950??2018-11-19?20:25??操作系統3\操作系統3\操作系統3.vcxproj.filters
?????文件?????????143??2018-11-19?20:09??操作系統3\操作系統3\操作系統3.vcxproj.user
?????文件????????3232??2018-11-20?20:53??操作系統3\操作系統3\最先算法.cpp
............此處省略3個文件信息
評論
共有 條評論