Hello,
I am trying to do a first fit allocation in java my problem is how do i keep track of which memory block i have cheked and if there are no suitable blocks put the job in a waiting queue.
Thanks for all help
import java.util.*;
import java.util.Scanner;
public class firstFit
{
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int[] blocks;
blocks = new int[4];
blocks[0] = 800;
blocks[1] = 900;
blocks[2] = 900;
blocks[3] = 300;
//Arrays.sort(blocks);
int[] jobs;
jobs = new int[3];
int index;
System.out.println("Enter 3 jobs:");
jobs[0] = keyboard.nextInt();
Arrays.sort(jobs);
for(index = 1; index < 3; index++){
jobs[index] = keyboard.nextInt();
}
for(int j=0; j<3;j++){
for(int i=0; i<4; i++){
if(jobs[j] <= blocks[i]){
blocks[i]=j;
System.out.println("Job" + jobs[j] + " in memory" + blocks[i]);
break;
}
else if(jobs[j] > blocks[i]){
System.out.println("Jobs in waiting queue " + jobs[j]);
}
}
}
}
}