Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > The execution time of quicksort algorithm in java.

Reply
Thread Tools

The execution time of quicksort algorithm in java.

 
 
arni arni is offline
Junior Member
Join Date: Jan 2010
Posts: 1
 
      01-04-2010
Hi, I have this quicksort algorithm and need to find its execution time in java, and I'm using eclipse. I tried it this way but there's something wrong with it I guess 'cause it still says the is an error. I would appreciate any help and advice!:

public class QuickSort {

long start = System.currentTimeMillis();

public static void main(String a[]){
int i;
int array[] = {7, 1, 5, 9, 120, 30, 55, 111,77};


System.out.println(" Quick Sort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
quick_srt(array,0,array.length-1);
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();

}

public static void quick_srt(int array[],int low, int n){
int lo = low;
int hi = n;
if (lo >= n) {
return;
}
int mid = array[(lo + hi) / 2];
while (lo < hi) {
while (lo<hi && array[lo] < mid) {
lo++;
}
while (lo<hi && array[hi] > mid) {
hi--;
}
if (lo < hi) {
int T = array[lo];
array[lo] = array[hi];
array[hi] = T;
}
}
if (hi < lo) {
int T = hi;
hi = lo;
lo = T;
}
quick_srt(array, low, lo);
quick_srt(array, lo == low ? lo+1 : lo, n);
}
long end = System.currentTimeMillis();
System.out.println("Execution time was" + (end-start) + "mlls");
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile time container, run-time execution. shar3ub@googlemail.com C++ 9 02-05-2009 09:26 AM
private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack sndive@gmail.com Python 9 11-14-2007 10:31 PM
Peterson's Algorithm in java, sequencial instruction execution ? xmarlawx@gmail.com Java 53 12-02-2006 07:03 PM
the quicksort algorithm in Numerical Recipes in C (2nd edition) Edward Hua C Programming 5 10-27-2005 05:30 PM
How to get asp execution time and database connection time ? Kelvin ASP General 1 07-13-2005 11:36 AM



Advertisments