銀行家算法主要核心代碼?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
class Process{
String name; //進程名字
int allocation[]; //已分配的資源數
int MaxNeed[]; //最大需求數量
int needs[]; //仍然需要
boolean finshined=false; //狀態,這個狀態用來指明進程分配過程的狀態
@Override
public String toString() {
return "Process{" +
"name='" + name + '\'' +
", allocation=" + Arrays.toString(allocation) +
//", MaxNeed=" + Arrays.toString(MaxNeed) + 可選項,最大需求矩陣不輸出
", needs=" + Arrays.toString(needs) +
", finshined=" + finshined +
'}';//重寫tostring方法,用來輸出進程信息
}
}
public class Bank {
private static int KINDS=0; //資源種類
private static int[] resource; //總資源數
private static int ProcessCount; //進程數量
private static List<Process> team;//進程數組
private static int[] avaliable; //當前可分配資源
public static void InitAllResource(