Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 02:37

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



another java problem about sorting a scheduling algorithm

Discussion on another java problem about sorting a scheduling algorithm within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 28
Received Thanks: 5
another java problem about sorting a scheduling algorithm

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?
morphling18 is offline  
Old 09/28/2012, 16:15   #2
 
omer36's Avatar
 
elite*gold: 0
Join Date: Mar 2009
Posts: 2,317
Received Thanks: 1,255
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] + "");
  }
omer36 is offline  
Thanks
1 User
Old 09/28/2012, 17:00   #3
 
elite*gold: 0
Join Date: Apr 2012
Posts: 28
Received Thanks: 5
thank you for this sir. i'll try this
morphling18 is offline  
Reply


Similar Threads Similar Threads
JAVA problem array sorting
09/28/2012 - General Coding - 1 Replies
i use three arrays where in System.out.println("Enter number of process: "); int process = in.nextInt(); String name = new String; int age = new int; double income = new double; bla bla bla so basically i used three arrays and a for loop and the outcome is this. (note: this is a user input)
[Just another graph-related algorithm] Kruskal`s algorithm
07/25/2012 - CO2 Programming - 11 Replies
(Scroll down for the code if you aren`t interested in my wall of text.) Okay, my previous post on Dijkstra`s algorithm didn`t really get the attention it was supposed to get, but I`m still starting a trend out of this. What exactly? I will be posting general purpose algorithms from time to time, as I truly believe that this is one of the most fundamental and important aspect of being a good coder : knowing the basic algorithms (lol?). If anyone can provide a way of implementing this in a CO...
Guild Siege Scheduling.
05/30/2012 - Flyff Private Server - 3 Replies
How to set guild siege every 3 hours?
[Tool] LoLEtal Sorting
03/29/2012 - League of Legends - 0 Replies
This is a little program I made to sort the accounts you want to bot. It compiles the list of all the completed accounts and accounts to check which ones are done or not and distribute the unfinished accounts among the bots. http://www.mediafire.com/?yyx0f8kfhbybkw1 Instructions: 1. Put the jar file in the folder with all the bots, like picture below; http://dl.dropbox.com/u/4962068/one.png 2. Run jar file, and it will tell you how many accounts unfinished;...
Sorting Everything out
04/22/2009 - Dekaron - 2 Replies
ok i had a friend who helped me put in my first hackes in when i played 2moons but now he got banned and dont play no more so i need help finding where things go i have unpacked dekaron, gameguardkiller and the laucher for it and the CE, but the only problem im having is that i cant seem to figure out where things go do i put the unpacked dekaron in the bin and the gameguardkiller in the gameguard folder? thats all im cofnused with if u have anyhting that can help me plzz post and tell me where...



All times are GMT +1. The time now is 02:37.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.