Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package thread;
- public class Main {
- static Process[] p = new Process[4];
- public static void main(String[] args) {
- setValues();
- for (int i = 0; i < 25; i++) {
- int lowIndex = -1, lowVal = Integer.MAX_VALUE;
- for (int j = 0; j < p.length; j++) {
- if(p[j].arrivalT <= i && p[j].burstT < lowVal){
- lowIndex = j;
- lowVal = p[j].burstT;
- }
- }
- }
- }
- static void setValues(){
- for (int i = 0; i < p.length; i++) {
- switch(i){
- case 0 : p[i] = new Process(i, 10, 3);
- break;
- case 1 : p[i] = new Process(i, 5, 0);
- break;
- case 2 : p[i] = new Process(i, 3, 8);
- break;
- case 3 : p[i] = new Process(i, 8, 5);
- break;
- }
- }
- for (int i = 0; i < p.length - 1; i++)
- {
- int index = i;
- for (int j = i + 1; j < p.length; j++){
- if (p[j].arrivalT <= p[index].arrivalT){
- index = j;
- if (p[j].arrivalT == p[index].arrivalT){
- if (p[j].burstT < p[index].burstT){
- index = j;
- } else {
- index = i;
- }
- }
- }
- }
- Process pT = p[index];
- p[index] = p[i];
- p[i] = pT;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement