The execution time of quicksort algorithm in java.

Discussion in 'Software' started by arni, Jan 4, 2010.

  1. arni

    arni

    Joined:
    Jan 4, 2010
    Messages:
    1
    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+" ");
    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+" ");
    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");
    }
    arni, Jan 4, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rafael
    Replies:
    1
    Views:
    3,190
  2. Matti Haveri

    iPhoto red eye removal algorithm

    Matti Haveri, Aug 8, 2003, in forum: Digital Photography
    Replies:
    0
    Views:
    509
    Matti Haveri
    Aug 8, 2003
  3. Glenn Nelson

    Kodak DX 4530 Compression Algorithm Question

    Glenn Nelson, Sep 24, 2003, in forum: Digital Photography
    Replies:
    4
    Views:
    448
    Ron Hunter
    Sep 24, 2003
  4. Prognathous

    What's the best downsizing algorithm?

    Prognathous, Nov 20, 2003, in forum: Digital Photography
    Replies:
    21
    Views:
    2,465
    BarryC at SkylarkDVD
    Dec 3, 2003
  5. krkrkr

    execution time

    krkrkr, Nov 7, 2009, in forum: Software
    Replies:
    0
    Views:
    1,154
    krkrkr
    Nov 7, 2009
Loading...

Share This Page