求银行家算法判断是否存在安全序列程序
堕落的天使 2008-11-19 12:20:48 #include<stdio.h>
#define M 3
#define N 5
void main()
{
int max[N][M],allocate[N][M],need[N][M],available[M];
int i,j,flag=1;
printf("\nThere are %d process in system!\n",N);
printf("\nPlease input the maxresource!\n");
for(i=0;i<N;i++)
{ printf("\nInput the maxresource of p%d:",i);
for(j=0;j<M;j++)
scanf("%d",&max[i][j]);
}
printf("\nPlease input the allocation!\n");
for(i=0;i<N;i++)
{ printf("\nInput the allocation of p%d:",i);
for(j=0;j<M;j++)
scanf("%d",&allocate[i][j]);
}
printf("\nplease Input the available of resources:");
for(i=0;i<M;i++)
scanf("%d",&available[i]);
for(i=0;i<N;i++)
{for(j=0;j<M;j++)
need[i][j]=max[i][j]-allocate[i][j];
}
printf("---------------------------------------------------------------\n");
printf("|ProcessId| Max | Allocation | Need | Available|\n");
printf("---------------------------------------------------------------\n");
for(i=0;i<N;i++)
{ printf("| P%d | %2d%2d%2d | %2d%2d%2d | %2d%2d%2d | %2d%2d%2d |\n",
i,max[i][0],max[i][1],max[i][2],
allocate[i][0],allocate[i][1],allocate[i][2],
need[i][0],need[i][1],need[i][2],
available[0],available[1],available[2]);
printf("---------------------------------------------------------------\n");
}
printf("\nThe order of request successfully process is:");
}
上面是一个银行家算法程序,在printf("\nThe order of request successfully process is:");语句后面缺少一个判断再输入数据后是否存在一个安全序列的程序 请高手指点!!!!!!谢谢!!!!!