banker.txt
资源名称:banker.rar [点击查看]
上传用户:pcon123456
上传日期:2022-07-14
资源大小:1k
文件大小:1k
源码类别:
操作系统开发
开发平台:
C/C++
- #include"math.h"
- #include"stdio.h"
- void main()
- {
- int allocation[5][3]={{0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2}};
- int Need[5][3]={{7,4,3},{1,2,2},{6,0,0},{0,1,1},{4,3,1}};
- int available[3]={3,3,2};
- int Finish[5]={0,0,0,0,0};
- int p[5];
- int num;
- int k=-1;
- label1: for(int i=0;i<5;i++)
- {
- num=0;
- if(Finish[i]==0)
- {
- for( int j=0;j<3;j++)
- {
- if(Need[i][j]<=available[j])
- num++;
- }
- if(num==3)
- {
- for( int j=0;j<3;j++)
- {available[j]=available[j]+allocation[i][j];}
- Finish[i]=1;
- k++;
- p[k]=i+1;
- if(k<4)
- {goto label1;}
- }
- }
- }
- if(k<4)
- printf("无安全序列");
- else
- {
- printf("存在安全序列其顺序为:");
- for(int a=0;a<5;a++)
- {printf("%d->",p[a]) ;}
- }
- }