-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstfit.java
45 lines (33 loc) · 1.29 KB
/
firstfit.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class firstfit {
static void firstFit(int blockSize[], int m, int processSize[], int n){
int allocation[] = new int[n];
for(int i = 0; i< allocation.length; i++)
allocation[i] = -1;
for(int i = 0; i<n; i++){
for(int j=0; j<m; j++){
if(blockSize[j] >= processSize[i]){
allocation[i] = j;
blockSize[j] -= processSize[i];
break;
}
}
}
System.out.println("Process no.\tProcess Size \tBlock no.");
for(int i = 0; i<n; i++){
System.out.print(" " + (i+1) + "\t\t" + processSize[i] + "\t\t");
if(allocation[i] != -1)
System.out.print(allocation[i] + 1);
else
System.out.print("Not allocated");
System.out.println();
}
}
public static void main(String [] args)
{
int blockSize[] = {100,500,200,300,600};
int processSize[] = {212,417,112,426};
int m = blockSize.length;
int n = processSize.length;
firstFit(blockSize,m,processSize,n);
}
}