标题:银行家算法
只看楼主
mouse816
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2006-10-9
 问题点数:0 回复次数:1 
银行家算法
请教操作系统的银行家算法实验用c语言怎么整出来啊,希望能给个详细说明,谢谢,急用....
搜索更多相关主题的帖子: 银行家 算法 
2006-11-30 20:06
mouse816
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2006-10-9
得分:0 

我找个一个,供大家参考

#include <stdio.h>

int main(int argc, char *argv[])
{
int claim[5][3] = {{7,5,3},{3,2,2},{9,0,2},{2,2,2},{4,3,3}};
int allocation[5][3] = {{0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2}};
int p,s = 0;
int count=0;
int need[5][3] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
int result[5] = {-1,-1,-1,-1,-1};
int work[3] = {3,3,2};


printf("all source:\n A B C\n 10 5 7\n");

printf("available:\n A B C\n 3 3 2\n");


printf("every max source:\n A B C\n");
for(p=0;p<5;p++){
printf("P%d: ",p);
for(s=0;s<3;s++){
printf(" %d ",claim[p][s]);
need[p][s]=claim[p][s]-allocation[p][s];
}
printf("\n");
}


printf("allocation:\n A B C\n");
for(p=0;p<5;p++){
printf("P%d: ",p);
for(s=0;s<3;s++)
printf(" %d ",allocation[p][s]);
printf("\n");
}


printf("every need:\n A B C\n");
for(p=0;p<5;p++){
printf("P%d: ",p);
for(s=0;s<3;s++)
printf(" %d ",need[p][s]);
printf("\n");
}

for(s=0;s<5;s++)
for(p=0;p<5;p++){
if(result[p]==-1&&need[p][0]<=work[0]&&need[p][1]<=work[1]&&need[p][2]<=work[2]){
work[0]=work[0]+allocation[p][0];
work[1]=work[1]+allocation[p][1];
work[2]=work[2]+allocation[p][2];
result[p]=s;count++;
printf("P%d->",p);
}
}

if(count==5)
printf("\nit is safe!\n");
else
printf("\nit is danger\n");
return 0;
}


喜欢一个人静静的思考....
2006-12-02 10:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-106402-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.937830 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved