欢迎来到天天文库
浏览记录
ID:60846997
大小:22.50 KB
页数:6页
时间:2020-12-22
《 银行家算法C++代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#defineFalse0#defineTrue1intMax[100][100]={0};//各进程所需各类资源的最大需求intAvaliable[100]={0};//系统可用资源charname[100]={0};//资源的名称intAllocation[100][100]={0};//系统已分配资源intNeed[100][100]={0};//还需要资源intRequest[100]={0};//请求资源向量intt
2、emp[100]={0};//存放安全序列intWork[100]={0};//存放系统可提供资源intM;//作业的最大数intN;//资源的最大数intSum[50]={0};voidinit(){inti,j,flag;charming;cout<<"请首先输入系统可供资源种类的数量:";cin>>N;for(i=0;i>ming;name[i]=ming;cout<<"资源的数量:";cin>>Sum[i];}cout<3、的数量:";cin>>M;cout<<"请输入各进程的最大需求量("<>Max[i][j];do{flag=0;cout<<"请输入各进程已经申请的资源量("<>Allocation[i][j];if(Allocation[i][j]>Max[i][j])fl4、ag=1;Need[i][j]=Max[i][j]-Allocation[i][j];}}while(flag);if(flag)cout<<"申请的资源大于最大需求量,请重新输入!";for(j=0;j5、j++){Avaliable[j]=Avaliable[j]+Request[j];Allocation[i][j]=Allocation[i][j]-Request[j];Need[i][j]=Need[i][j]+Request[j];}}voidshowdata()//显示资源矩阵{inti,j;cout<<"MaxAllocationNeed"<6、r(i=0;i7、tion[i][j]=Allocation[i][j]+Request[j];Need[i][j]=Need[i][j]-Request[j];}return1;}intsafe()//安全性算法{inti=0,k=0,m,apply,Finish[100]={0};intj;intflag=0;Work[0]=Avaliable[0];Work[1]=Avaliable[1];Work[2]=Avaliable[2];for(i=0;i8、lse&&Need[i][j]<=Work[j]){apply++;if(apply==N){for(m=0;m
3、的数量:";cin>>M;cout<<"请输入各进程的最大需求量("<>Max[i][j];do{flag=0;cout<<"请输入各进程已经申请的资源量("<>Allocation[i][j];if(Allocation[i][j]>Max[i][j])fl
4、ag=1;Need[i][j]=Max[i][j]-Allocation[i][j];}}while(flag);if(flag)cout<<"申请的资源大于最大需求量,请重新输入!";for(j=0;j5、j++){Avaliable[j]=Avaliable[j]+Request[j];Allocation[i][j]=Allocation[i][j]-Request[j];Need[i][j]=Need[i][j]+Request[j];}}voidshowdata()//显示资源矩阵{inti,j;cout<<"MaxAllocationNeed"<6、r(i=0;i7、tion[i][j]=Allocation[i][j]+Request[j];Need[i][j]=Need[i][j]-Request[j];}return1;}intsafe()//安全性算法{inti=0,k=0,m,apply,Finish[100]={0};intj;intflag=0;Work[0]=Avaliable[0];Work[1]=Avaliable[1];Work[2]=Avaliable[2];for(i=0;i8、lse&&Need[i][j]<=Work[j]){apply++;if(apply==N){for(m=0;m
5、j++){Avaliable[j]=Avaliable[j]+Request[j];Allocation[i][j]=Allocation[i][j]-Request[j];Need[i][j]=Need[i][j]+Request[j];}}voidshowdata()//显示资源矩阵{inti,j;cout<<"MaxAllocationNeed"<6、r(i=0;i7、tion[i][j]=Allocation[i][j]+Request[j];Need[i][j]=Need[i][j]-Request[j];}return1;}intsafe()//安全性算法{inti=0,k=0,m,apply,Finish[100]={0};intj;intflag=0;Work[0]=Avaliable[0];Work[1]=Avaliable[1];Work[2]=Avaliable[2];for(i=0;i8、lse&&Need[i][j]<=Work[j]){apply++;if(apply==N){for(m=0;m
6、r(i=0;i7、tion[i][j]=Allocation[i][j]+Request[j];Need[i][j]=Need[i][j]-Request[j];}return1;}intsafe()//安全性算法{inti=0,k=0,m,apply,Finish[100]={0};intj;intflag=0;Work[0]=Avaliable[0];Work[1]=Avaliable[1];Work[2]=Avaliable[2];for(i=0;i8、lse&&Need[i][j]<=Work[j]){apply++;if(apply==N){for(m=0;m
7、tion[i][j]=Allocation[i][j]+Request[j];Need[i][j]=Need[i][j]-Request[j];}return1;}intsafe()//安全性算法{inti=0,k=0,m,apply,Finish[100]={0};intj;intflag=0;Work[0]=Avaliable[0];Work[1]=Avaliable[1];Work[2]=Avaliable[2];for(i=0;i8、lse&&Need[i][j]<=Work[j]){apply++;if(apply==N){for(m=0;m
8、lse&&Need[i][j]<=Work[j]){apply++;if(apply==N){for(m=0;m
此文档下载收益归作者所有