public static < T extends Comparable < ? super T > > void sort ( T [ ] a , int lo0 , int hi0 ) { // bail out if we're already done if ( hi0 <= lo0 ) { return ; } T t ; // if this is a two element file, do a simple sort on it if ( hi0 - lo0 == 1 ) { // if they're not already sorted, swap them if ( a [ lo0 ] . compareTo ( a [ hi0 ] ) > 0 ) { t = a [ lo0 ] ; a [ lo0 ] = a [ hi0 ] ; a [ hi0 ] = t ; } return ; } // the middle element in the array is our partitioning element T mid = a [ ( lo0 + hi0 ) >>> 1 ] ; // set up our partitioning boundaries int lo = lo0 - 1 , hi = hi0 + 1 ; // loop through the array until indices cross for ( ; ; ) { // find the first element that is greater than or equal to the partition element // starting from the left Index. while ( mid . compareTo ( a [ ++ lo ] ) > 0 ) { /* loop! */ } // find an element that is smaller than or equal to the partition element starting from // the right Index. while ( mid . compareTo ( a [ -- hi ] ) < 0 ) { /* loop! */ } // swap the two elements or bail out of the loop if ( hi > lo ) { t = a [ lo ] ; a [ lo ] = a [ hi ] ; a [ hi ] = t ; } else { break ; } } // if the right index has not reached the left side of array must now sort the left // partition if ( lo0 < lo - 1 ) { sort ( a , lo0 , lo - 1 ) ; } // if the left index has not reached the right side of array must now sort the right // partition if ( hi + 1 < hi0 ) { sort ( a , hi + 1 , hi0 ) ; } }
Sorts the specified subset of the supplied array of comparables from least to greatest using the supplied comparator .