level 1
appsli
楼主
#include <iostream.h>
int work[10][2]; //作业名字 大小
int idle[10][2]; //空闲区大小 地址
int free[10][3]; //已分配区域的名字 地址 大小
int num=0,b=1,d,ch1,ch2;
void init(){
idle[0][0]=1;idle[0][1]=100;
free[0][0]=0;free[1][1]=0;free[1][2]=0;
work[0][0]=0;work[0][1]=0;
for(int i=1;i <=9;i++){ //初始化数组
idle[i][0]=0;idle[i][1]=0;
free[i][0]=0;free[i][1]=0;free[i][2]=0;
work[i][0]=0;work[i][1]=0;
}
}
void jishu(){ //求空闲单元数
for(int i=0;i <9;i++)
if(idle[i][1]!=0)
num++;
}
void jishu1(){ //求作业数
for(int i=0;i <9;i++)
if(work[i][1]!=0)
b++;
}
void zuixian(){ //最先适应法
jishu();
for(int i=0;i <num;i++){
for(int j=i;j <num-i-1;j++){
if(idle[j][0]>idle[j+1][0]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
}
void zuijia(){ //最佳适应法
num=0;
jishu();
for(int i=0;i <num;i++){
for(int j=i;j <num-i-1;j++){
if(idle[j][1]>idle[j+1][1]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
}
void zuihuai(){ //最坏适应法
num=0;
jishu();
for(int i=0;i <num;i++){
for(int j=i;j <num-i-1;j++){
if(idle[j][1] <idle[j+1][1]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
}
void huishou(int name){ //回收进程函数
num=0;
b=0;
jishu();
jishu1();
int c=-1;
for(int k=0;k <=b;k++){
if(free[k][0]==name){
c=k;
break;
}
}
if(c==-1)cout <<"要回收的作业不存在!" <<endl;
else{
for(int i=0;i <num;i++){ //将空闲单元排序{不包括新回收的}
for(int j=i;j <num-i-1;j++){
if(idle[j][0]>idle[j+1][0]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
for(int q=0;q <num;q++){ //将空单元排序{包括新回收的}
if(free[c][1] <=idle[q][0]){
2012年06月17日 03点06分
1
int work[10][2]; //作业名字 大小
int idle[10][2]; //空闲区大小 地址
int free[10][3]; //已分配区域的名字 地址 大小
int num=0,b=1,d,ch1,ch2;
void init(){
idle[0][0]=1;idle[0][1]=100;
free[0][0]=0;free[1][1]=0;free[1][2]=0;
work[0][0]=0;work[0][1]=0;
for(int i=1;i <=9;i++){ //初始化数组
idle[i][0]=0;idle[i][1]=0;
free[i][0]=0;free[i][1]=0;free[i][2]=0;
work[i][0]=0;work[i][1]=0;
}
}
void jishu(){ //求空闲单元数
for(int i=0;i <9;i++)
if(idle[i][1]!=0)
num++;
}
void jishu1(){ //求作业数
for(int i=0;i <9;i++)
if(work[i][1]!=0)
b++;
}
void zuixian(){ //最先适应法
jishu();
for(int i=0;i <num;i++){
for(int j=i;j <num-i-1;j++){
if(idle[j][0]>idle[j+1][0]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
}
void zuijia(){ //最佳适应法
num=0;
jishu();
for(int i=0;i <num;i++){
for(int j=i;j <num-i-1;j++){
if(idle[j][1]>idle[j+1][1]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
}
void zuihuai(){ //最坏适应法
num=0;
jishu();
for(int i=0;i <num;i++){
for(int j=i;j <num-i-1;j++){
if(idle[j][1] <idle[j+1][1]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
}
void huishou(int name){ //回收进程函数
num=0;
b=0;
jishu();
jishu1();
int c=-1;
for(int k=0;k <=b;k++){
if(free[k][0]==name){
c=k;
break;
}
}
if(c==-1)cout <<"要回收的作业不存在!" <<endl;
else{
for(int i=0;i <num;i++){ //将空闲单元排序{不包括新回收的}
for(int j=i;j <num-i-1;j++){
if(idle[j][0]>idle[j+1][0]){
int temp=idle[j][0];
idle[j][0]=idle[j+1][0];
idle[j+1][0]=temp;
temp=idle[j][1];
idle[j][1]=idle[j+1][1];
idle[j+1][1]=temp;
}
}
}
for(int q=0;q <num;q++){ //将空单元排序{包括新回收的}
if(free[c][1] <=idle[q][0]){