Contents    Page-10    Prev    Next    Page+10    Index   

Quicksort Code[This version of Quicksort is from H. W. Lang, Fachhochschule Flensburg, http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/quick/quicken.htm ]


public static void quicksort(
  Integer[] a, int lo, int hi ) {
    int i=lo, j=hi; Integer h;
    Integer pivot = a[(lo+hi)/2];

    do                              //  partition
    {    
        while (a[i] < pivot) i++;         // move
        while (a[j] > pivot) j--;
        if (i<=j)
        {
            h=a[i]; a[i]=a[j]; a[j]=h;    // swap
            i++; j--;
        }
    } while (i<=j);

    if (lo<j) quicksort(a, lo, j);  //  recursion
    if (i<hi) quicksort(a, i, hi);
}