经典算法 java实现
部分代码
// 系统拥有的初始资源数
public static int AVAILABLE[] = { 10, 5, 7 };
// 系统已给每个进程分配的资源数
public static int ALLOCATION[][] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
{ 0, 0, 0 }, { 0, 0, 0 } };
// 每个进程还需要的资源数
public static int NEED[][] = { { 7, 5, 3 }, { 3, 2, 2 }, { 9, 0, 2 },
{ 2, 2, 2 }, { 4, 3, 3 } };
// 每次申请的资源数
public static int Request[] = { 0, 0, 0 };
// 进程数与资源数
public static int M = 5, N = 3;
int FALSE = 0;
int TRUE = 1;
public void showdata() {
int i, j;
System.out.print("系统可用的资源数为:/n");
for (j = 0; j < N; j++) {
System.out.print("资源" + j + ":" + AVAILABLE[j] + " ");
}
System.out.println();
System.out.println("各进程还需要的资源量:");
for (i = 0; i < M; i++) {
System.out.print("进程" + i + ":");
for (j = 0; j < N; j++) {
System.out.print("资源" + j + ":" + NEED[i][j] + " ");
}
System.out.print("/n");
}
System.out.print("各进程已经得到的资源量: /n");
for (i = 0; i < M; i++) {
System.out.print("进程");
System.out.print(i);
for (j = 0; j < N; j++) {
System.out.print("资源" + j + ":" + ALLOCATION[i][j] + " ");
}
System.out.print("/n");