another java problem about sorting a scheduling algorithm

09/28/2012 12:39 morphling18#1
i've tried to use 3 arrays which are

System.out.println("enter number of process: ");
int process = in.nextInt();

String name[] = new String[process];
int ArrivalT[] = new int[process];
int BurstT[] = new int[process];

and then i've used for loop for inputs of name, BT and AT.
i've also got the Average turn around time(ATAT) wherein i sum up all the burst time and then divided it by the number of process.
=================================
|| PROCESS || BT || AT ||
|| P1 || 10 || 2 ||
|| P2 || 6 || 1 ||
|| P3 || 8 || 0 ||
=================================
Average Turn Around Time: 8.00 ms
=================================

so my problem is i don't know how to get first the lowest AT and display it first then sort the rest by lowest to highest BT and still after i get and sorted the values, it will still be linked with each other. this is what i want to get after sorting

=================================
|| PROCESS || BT || AT ||
|| P3 || 8 || 0 || <]===== display first the lowest AT
|| P2 || 6 || 1 || <]=====then afterwise sort the BT from lowest to highest.
|| P1 || 10 || 2 ||
=================================

can anybody help me? what should i do?
09/28/2012 16:15 omer36#2
try it with bubble sort...

Code:
  int process = 3;
  String name[] = {"P1", "P2", "P3"};
  int BurstT[] = {10, 6, 8};
  int ArrivalT[] = {2, 1, 0};
  int tempAT, tempBT;
  String tempname;
  boolean check = false;

  do{
    check=false;
      for (int i=0;i < (process-1); i++){
       if (ArrivalT[i] > ArrivalT[i+1]){
         tempAT=ArrivalT[i];
         ArrivalT[i]=ArrivalT[i+1];
         ArrivalT[i+1]=tempAT;

         tempBT=BurstT[i];
         BurstT[i]=BurstT[i+1];
         BurstT[i+1]=tempBT;
         
         tempname= name[i];
         name[i]= name[i+1];
         name[i+1]=tempname;

         check=true;
         }
      }
  }while(check);

  for(int x=0;x!=process;x++) {
    System.out.println("||" + name[x] + "||" + BurstT[x] + "||" + ArrivalT[x] + "");
  }
09/28/2012 17:00 morphling18#3
thank you for this sir. i'll try this