var Max_source = 50 //最大进程数
var Max_process = 50 //最大资源数
class bank
{
//可用资源数
var available = [Int](repeating: 0, count: Max_source)
//最大需求
var max = [[Int]](repeating: [Int](repeating: 0, count: Max_source), count: Max_process)
//已分配资源数
var allocation = [[Int]](repeating: [Int](repeating: 0, count: Max_source), count: Max_process)
//还需资源数
var need = [[Int]](repeating: [Int](repeating: 0, count: Max_source), count: Max_process)
//进程需要资源数
var request = [[Int]](repeating: [Int](repeating: 0, count: Max_source), count: Max_process)
//判断系统是否有足够的资源分配
var finish = [Bool](repeating: true, count: Max_process)
//记录序列
var p = [Int](repeating: 0, count: Max_process)
var m:Int = 0;//用来表示进程
var n:Int = 0;//表示资源
func Init() {
print("请输入进程的数目:")
m = Int(readLine()!) ?? 0
print("请输入资源的数目:")
n = Int(readLine()!) ?? 0
print("请输入每个进程最多所需的各资源数,按照 \(m) X \(n) 矩阵格式输入")
for i in 0..
Swift4实现银行家算法
最新推荐文章于 2021-01-01 17:18:04 发布