我编的内存动态分配方法:首次适应算法
感兴趣的大虾们给提提意见吧^_^
#include <iostream.h>
#define n 10
void main()
{
int memory[n]={1,2,3,4,5,6,7,8,9,10};
static int point=0;
int request;
int get=1;
int ppoint;
cout<<"内存分区:"<<endl;
for(int i=0;i<n;i++)
{
cout<<memory[i]<<" ";
}
cout<<endl;
while(get==1)
{
cout<<"进程大小:";
cin>>request;
for(int i=0;i<n;i++)
{
ppoint=i;
if(request<=memory[ppoint])
{
memory[ppoint]-=request;
cout<<"内存 "<<ppoint+1<<" 完成分配!"<<endl;
cout<<"内存 :"<<endl;
for(int i=0;i<n;i++)
{
cout<<memory[i]<<" ";
}
cout<<endl;
break;
}
else
cout<<"内存 : "<<ppoint+1<<" 没有合适空间"<<endl;
}
cout<<"继续输入(0 or 1):";
cin>>get;
}
}