?? bankp.c
字號:
struct bank{
int Max[6][4];
int Allocation[6][4];
int Need[6][4];
int Available[4];
}p[6];
int Work[4];
int Finish[6]={0,0,0,0,0,0};
int W[7][4];
int p[6];
char F[7]={T,T,T,T,T,T,T}
p[1]->Max[1][1]=7;
p[1]->Max[1][2]=5;
p[1]->Max[1][3]=3;
p[1]->Allocation[1][1]=0;
p[1]->Allocation[1][2]=1;
p[1]->Allocation[1][3]=0;
p[1]->Need[1][1]=7;
p[1]->Need[1][2]=4;
p[1]->Need[1][3]=3;
p[1]->Available[1]=3;
p[1]->Available[2]=3;
p[1]->available[3]=2;
p[1]->Max[2][1]=3;
p[1]->Max[2][2]=3;
p[1]->Max[2][3]=2;
p[1]->Allocation[2][1]=2;
p[1]->Allocation[2][2]=0;
p[1]->Allocation[2][3]=0;
p[1]->Need[2][1]=1;
p[1]->Need[2][2]=2;
p[1]->Need[2][3]=2;
p[1]->Max[3][1]=9;
p[1]->Max[3][2]=0;
p[1]->Max[3][3]=2;
p[1]->Allocation[3][1]=3;
p[1]->Allocation[3][2]=0;
p[1]->Allocation[3][3]=2;
p[1]->Need[3][1]=6;
p[1]->Need[3][2]=0;
p[1]->Need[3][3]=0;
p[1]->Max[4][1]=2;
p[1]->Max[4][2]=2;
p[1]->Max[4][3]=2;
p[1]->Allocation[4][1]=2;
p[1]->Allocation[4][2]=2;
p[1]->Allocation[4][3]=1;
p[1]->Need[4][1]=0;
p[1]->Need[4][2]=1;
p[1]->Need[4][3]=1;
p[1]->Max[5][1]=4;
p[1]->Max[5][2]=3;
p[1]->Max[5][3]=3;
p[1]->Allocation[5][1]=0;
p[1]->Allocation[5][2]=0;
p[1]->Allocation[5][3]=2;
p[1]->Need[5][1]=4;
p[1]->Need[5][2]=3;
p[1]->Need[5][3]=1;
p[2]->Max[1][1]=5;
p[2]->Max[1][2]=5;
p[2]->Max[1][3]=9;
p[2]->Allocation[1][1]=2;
p[2]->Allocation[1][2]=1;
p[2]->Allocation[1][3]=2;
p[2]->Need[1][1]=3;
p[2]->Need[1][2]=4;
p[2]->Need[1][3]=7;
p[2]->Available[1]=2;
p[2]->Available[2]=3;
p[2]->available[3]=3;
p[2]->Max[2][1]=5;
p[2]->Max[2][2]=3;
p[2]->Max[2][3]=6;
p[2]->Allocation[2][1]=4;
p[2]->Allocation[2][2]=0;
p[2]->Allocation[2][3]=2;
p[2]->Need[2][1]=1;
p[2]->Need[2][2]=3;
p[2]->Need[2][3]=4;
p[2]->Max[3][1]=4;
p[2]->Max[3][2]=0;
p[2]->Max[3][3]=11;
p[2]->Allocation[3][1]=4;
p[2]->Allocation[3][2]=0;
p[2]->Allocation[3][3]=5;
p[2]->Need[3][1]=0;
p[2]->Need[3][2]=0;
p[2]->Need[3][3]=6;
p[2]->Max[4][1]=4;
p[2]->Max[4][2]=2;
p[2]->Max[4][3]=5;
p[2]->Allocation[4][1]=2;
p[2]->Allocation[4][2]=0;
p[2]->Allocation[4][3]=4;
p[2]->Need[4][1]=2;
p[2]->Need[4][2]=2;
p[2]->Need[4][3]=1;
p[2]->Max[5][1]=4;
p[2]->Max[5][2]=2;
p[2]->Max[5][3]=4;
p[2]->Allocation[5][1]=3;
p[2]->Allocation[5][2]=1;
p[2]->Allocation[5][3]=4;
p[2]->Need[5][1]=1;
p[2]->Need[5][2]=1;
p[2]->Need[5][3]=0;
p[3]->Max[1][1]=0;
p[3]->Max[1][2]=0;
p[3]->Max[1][3]=4;
p[3]->Allocation[1][1]=0;
p[3]->Allocation[1][2]=0;
p[3]->Allocation[1][3]=3;
p[3]->Need[1][1]=0;
p[3]->Need[1][2]=0;
p[3]->Need[1][3]=1;
p[3]->Available[1]=1;
p[3]->Available[2]=6;
p[3]->available[3]=2;
p[3]->Max[2][1]=2;
p[3]->Max[2][2]=7;
p[3]->Max[2][3]=5;
p[3]->Allocation[2][1]=1;
p[3]->Allocation[2][2]=0;
p[3]->Allocation[2][3]=0;
p[3]->Need[2][1]=1;
p[3]->Need[2][2]=7;
p[3]->Need[2][3]=5;
p[3]->Max[3][1]=3;
p[3]->Max[3][2]=6;
p[3]->Max[3][3]=10;
p[3]->Allocation[3][1]=1;
p[3]->Allocation[3][2]=3;
p[3]->Allocation[3][3]=5;
p[3]->Need[3][1]=2;
p[3]->Need[3][2]=3;
p[3]->Need[3][3]=5;
p[3]->Max[4][1]=0;
p[3]->Max[4][2]=9;
p[3]->Max[4][3]=8;
p[3]->Allocation[4][1]=0;
p[3]->Allocation[4][2]=3;
p[3]->Allocation[4][3]=3;
p[3]->Need[4][1]=0;
p[3]->Need[4][2]=6;
p[3]->Need[4][3]=5;
p[3]->Max[5][1]=0;
p[3]->Max[5][2]=6;
p[3]->Max[5][3]=6;
p[3]->Allocation[5][1]=0;
p[3]->Allocation[5][2]=0;
p[3]->Allocation[5][3]=1;
p[3]->Need[5][1]=0;
p[3]->Need[5][2]=6;
p[3]->Need[5][3]=5;
p[1]->Max[1][1]=5;
p[1]->Max[1][2]=5;
p[1]->Max[1][3]=9;
p[1]->Allocation[1][1]=2;
p[1]->Allocation[1][2]=3;
p[1]->Allocation[1][3]=2;
p[1]->Need[1][1]=3;
p[1]->Need[1][2]=2;
p[1]->Need[1][3]=7;
p[1]->Available[1]=0;
p[1]->Available[2]=1;
p[1]->available[3]=2;
p[1]->Max[2][1]=5;
p[1]->Max[2][2]=3;
p[1]->Max[2][3]=6;
p[1]->Allocation[2][1]=4;
p[1]->Allocation[2][2]=0;
p[1]->Allocation[2][3]=2;
p[1]->Need[2][1]=1;
p[1]->Need[2][2]=3;
p[1]->Need[2][3]=4;
p[1]->Max[3][1]=4;
p[1]->Max[3][2]=0;
p[1]->Max[3][3]=11;
p[1]->Allocation[3][1]=3;
p[1]->Allocation[3][2]=0;
p[1]->Allocation[3][3]=2;
p[1]->Need[3][1]=6;
p[1]->Need[3][2]=0;
p[1]->Need[3][3]=0;
p[1]->Max[4][1]=2;
p[1]->Max[4][2]=2;
p[1]->Max[4][3]=2;
p[1]->Allocation[4][1]=2;
p[1]->Allocation[4][2]=2;
p[1]->Allocation[4][3]=1;
p[1]->Need[4][1]=0;
p[1]->Need[4][2]=1;
p[1]->Need[4][3]=1;
p[1]->Max[5][1]=4;
p[1]->Max[5][2]=3;
p[1]->Max[5][3]=3;
p[1]->Allocation[5][1]=0;
p[1]->Allocation[5][2]=0;
p[1]->Allocation[5][3]=2;
p[1]->Need[5][1]=4;
p[1]->Need[5][2]=3;
p[1]->Need[5][3]=1;
main()
{ int i,j,k,L,m=0,n=0,t=1;
char b;
int h;
printf("input a number(1-5)and choose a group programe :");
scanf("%d",&h);
First_print(h);
printf("Do you want to use banker arithmetic(Y/N)");
if (b==Y||b==y)
{for(i=1;i<4;i++)
work[i]=p[h]->available[i];
for(i=1;i<6;i++)
{ for(j=1;j<6:j++)
if(!Finish[j])
{for(k=1;k<4;k++)
if (work[k]>=p[h]->Nedd[j][k])
m++;
if(m==3)
{ Finish[j]=1;
for(k=1;k<4;k++)
Work[k]=Work[k]+p[h]->Allocation[j][k];
WA[j][k]=Work[k];
W[j+1][k]=WA[j][k];
F[t++]=T;P[t++]=j;
printf("No.%d times process p%d passed;",i,j);
}
else printf("No.%d times process p%d don't passed",i,j);
}
for(k=1;k<=5;k++)
if(Finish[k]==1)n=n+1;
if(n==5)i=5;
else n=0;
}
m=0;n=1;
for(k=1;k<=5;k++)
{if(finish[k]==1)m=m+1;
else{printf("the last process p%d don't passed",k);
n=0;
}
if(n)printf("the system is safty!");
else printf("the system isn't safty!");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -