一个关于操作系统银行家算法的程序,有点问题,请哪位大神帮忙解决一下! 15

typedefstructResource{intR[3];}Max,Alloc,Need,Avail,Request,Work,WA;typedefstruct{str... typedef struct Resource{
int R[3];
} Max,Alloc,Need, Avail,Request,Work,WA;

typedef struct{
struct Resource Max;
struct Resource Alloc;
struct Resource Need;
struct Resource Avail;
struct Resource Request;
struct Resource Work;
struct Resource WA;
int Finish;
}Process;
int InitStatus(Process P[],int n)
{
int i,j;
//Process P[100];

//printf("输入三种资源当前可用数:");
//scanf("%d %d %d",&a,&b,&c);

for(i=1;i<=n;i++)
{
printf("创建第%d个进程的初始资源状态\n",i);
printf("输入三种资源最大需求量:");
for(j=0;j<3;j++)
{
scanf("%d",&P[i].Max.R[j]);
}
printf("输入三种资源已分配数:");
for(j=0;j<3;j++){
scanf("%d",&P[i].Alloc.R[j]);
}
printf("输入三种资源还需要数:");
for(j=0;j<3;j++){
scanf("%d",&P[i].Need.R[j]);
}
printf("\n");
} return n;
}
void Print(Process P[],int i){

printf("\t 进程名 \t Max \t Allocation \t Need \t\n");
printf("\t %d \t %d %d %d \t %d %d %d\t %d %d %d \t \n",i,P[i].Max.R [0],P[i].Max.R[1],P[i].Max .R [2],P[i].Alloc .R [0],P[i].Alloc .R [1],P[i].Alloc .R [2],P[i].Need .R [0],P[i].Need .R [1],P[i].Need .R [2]);
}
int Change(Process P,Resource Available)
{
int i,m;
for(i=0;i<3;i++)
{
P.Avail.R[i]=Available.R[i]-P.Request.R[i];
P.Alloc.R[i]=P.Alloc.R[i]-P.Request.R[i];
P.Need.R[i]=P.Need.R[i]-P.Request.R[i];
}
for(m=0;m<3;m++)
{
printf("%d ",&Available.R [m]);
}
printf("\n");
return ok;
}
int Safety(Process P)

{
int i;
for(i=0;i<3;i++)
{
P.Work.R[i]=P.Avail.R[i];
}
P.Finish=False;
for(i=0;i<3;i++)
{
if(P.Work.R[i]<=P.Need.R[i])
{
P.WA.R[i]=P.Work.R[i]+P.Alloc.R[i];
P.Finish=True;return 0;
}

}

return ok;
}
展开
 我来答
tbyang2011
2013-06-10 · TA获得超过681个赞
知道小有建树答主
回答量:778
采纳率:50%
帮助的人:355万
展开全部
#include <stdio.h>

typedef struct Resource{
int R[3];
} Max,Alloc,Need, Avail,Request,Work,WA;

typedef struct{
struct Resource Max;
struct Resource Alloc;
struct Resource Need;
struct Resource Avail;
struct Resource Request;
struct Resource Work;
struct Resource WA;
int Finish;
}Process;
int InitStatus(Process P[],int n)
{
int i,j;
//Process P[100];

//printf("输入三种资源当前可用数:");
//scanf("%d %d %d",&a,&b,&c);

for(i=1;i<=n;i++)
{
printf("创建第%d个进程的初始资源状态\n",i);
printf("输入三种资源最大需求量:");
for(j=0;j<3;j++)
{
scanf("%d",&P[i].Max.R[j]);
}
printf("输入三种资源已分配数:");
for(j=0;j<3;j++){
scanf("%d",&P[i].Alloc.R[j]);
}
printf("输入三种资源还需要数:");
for(j=0;j<3;j++){
scanf("%d",&P[i].Need.R[j]);
}
printf("\n");
} return n;
}
void Print(Process P[],int i){

printf("\t 进程名 \t Max \t Allocation \t Need \t\n");
printf("\t %d \t %d %d %d \t %d %d %d\t %d %d %d \t \n",i,P[i].Max.R [0],P[i].Max.R[1],P[i].Max .R [2],P[i].Alloc .R [0],P[i].Alloc .R [1],P[i].Alloc .R [2],P[i].Need .R [0],P[i].Need .R [1],P[i].Need .R [2]);
}
int Change(Process P,Resource Available)
{
int i,m;
for(i=0;i<3;i++)
{
P.Avail.R[i]=Available.R[i]-P.Request.R[i];
P.Alloc.R[i]=P.Alloc.R[i]-P.Request.R[i];
P.Need.R[i]=P.Need.R[i]-P.Request.R[i];
}
for(m=0;m<3;m++)
{
printf("%d ",&Available.R [m]);
}
printf("\n");
return 1; // return ok; // ok' : undeclared identifier
}
int Safety(Process P)

{
int i;
for(i=0;i<3;i++)
{
P.Work.R[i]=P.Avail.R[i];
}
P.Finish=false; // P.Finish=False; // 'False' : undeclared identifier
for(i=0;i<3;i++)
{
if(P.Work.R[i]<=P.Need.R[i])
{
P.WA.R[i]=P.Work.R[i]+P.Alloc.R[i];
P.Finish=true; // P.Finish=True; // 'True' : undeclared identifier
return 0;
}

}

return 1; // return ok; // 'ok' : undeclared identifier
}

void main(){}
追问
谢谢,但重点是我想知道算法哪里出了问题?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
亚远景信息科技
2024-12-11 广告
上海亚远景信息科技有限公司是国内汽车行业咨询及评估领军机构之一,深耕于ASPICE、敏捷SPICE、ISO26262功能安全、ISO21434车辆网络安全领域,拥有20年以上的行业经验,专精于培训、咨询及评估服务,广受全球车厂及供应商赞誉,... 点击进入详情页
本回答由亚远景信息科技提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式