SJF
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter number of process");
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] ar = new int[n];
int[] bt = new int[n];
int[] ct = new int[n];
int[] ta = new int[n];
int[] wt = new int[n];
int[] pid = new int[n];
int[] f = new int[n];
int st = 0, tot = 0;
for(int i = 0; i < n; i++){
System.out.println("Enter process" + (i + 1) + "arrival time");
ar[i] = in.nextInt();
System.out.println("Enter process" + (i + 1) + "burst time");
bt[i] = in.nextInt();
pid[i] = i + 1;
f[i] = 0;
}
while(true){
int c = n;
int min = 99999;
if(tot == n) break;
for(int i = 0; i < n; i++){
if((ar[i] <= st) && (f[i] == 0) && (bt[i] < min)){
min = bt[i];
c = i;
}
}
if(c == n){
st++;
}
else{
ct[c] = st + bt[c];
st = st + bt[c];
ta[c] = ct[c] - ar[c];
wt[c] = ta[c] - bt[c];
f[c] = 1;
pid[tot] = c + 1;
tot++;
}
}
System.out.println("Process" + " " + "AT" + " " + "BT" + " " + "CT" + " " + "TAT" + " " + "WT");
for(int i = 0; i < n; i++){
System.out.println(pid[i] + " " + ar[i] + " " + bt[i] + " " + ct[i] + " " + ta[i] + " " + wt[i]);
}
}
}
Comments
Post a Comment