public static void sortData ( final Object [ ] data , final Comparator < Object > comparator , final boolean ascending , final int lowIndex , final int highIndex , final int [ ] sortIndices ) { if ( lowIndex >= highIndex ) { return ; // 1 element, so sorted already! } Object midValue = data [ sortIndices [ ( lowIndex + highIndex ) >>> 1 ] ] ; int i = lowIndex - 1 ; int j = highIndex + 1 ; int sign = ascending ? 1 : - 1 ; for ( ; ; ) { do { i ++ ; } while ( comparator . compare ( data [ sortIndices [ i ] ] , midValue ) * sign < 0 ) ; do { j -- ; } while ( comparator . compare ( data [ sortIndices [ j ] ] , midValue ) * sign > 0 ) ; if ( i >= j ) { break ; // crossover, good! } // Out of order - swap! int temp = sortIndices [ i ] ; sortIndices [ i ] = sortIndices [ j ] ; sortIndices [ j ] = temp ; } // now determine the split point... if ( i > j ) { i = j ; } sortData ( data , comparator , ascending , lowIndex , i , sortIndices ) ; sortData ( data , comparator , ascending , i + 1 , highIndex , sortIndices ) ; }
Sorts the data using the given comparator using a quick - sort .