private static void sort1 ( Quicksortable q , int off , int k , int len ) { // we don't care about anything >= to k if ( off >= k ) return ; // Insertion sort on smallest arrays if ( len < 7 ) { for ( int i = off ; i < len + off ; i ++ ) for ( int j = i ; j > off && q . compare ( j , j - 1 ) < 0 ; j -- ) q . swap ( j , j - 1 ) ; return ; } // Choose a partition element, v int m = off + ( len >> 1 ) ; // Small arrays, middle element if ( len > 7 ) { int l = off ; int n = off + len - 1 ; if ( len > 40 ) { // Big arrays, pseudomedian of 9 int s = len / 8 ; l = med3 ( q , l , l + s , l + 2 * s ) ; m = med3 ( q , m - s , m , m + s ) ; n = med3 ( q , n - 2 * s , n - s , n ) ; } m = med3 ( q , l , m , n ) ; // Mid-size, med of 3 } // move the pivot element to to the front q . swap ( off , m ) ; m = off ; // Establish Invariant: m* (<m)* (>m)* m* int a = off + 1 , b = a , c = off + len - 1 , d = c ; int cmp ; while ( true ) { while ( b <= c && ( cmp = q . compare ( b , off ) ) <= 0 ) { if ( cmp == 0 ) q . swap ( a ++ , b ) ; b ++ ; } while ( c >= b && ( cmp = q . compare ( c , off ) ) >= 0 ) { if ( cmp == 0 ) q . swap ( c , d -- ) ; c -- ; } if ( b > c ) break ; q . swap ( b ++ , c -- ) ; } // Swap partition elements back to middle int s , n = off + len ; s = Math . min ( a - off , b - a ) ; vecswap ( q , off , b - s , s ) ; s = Math . min ( d - c , n - d - 1 ) ; vecswap ( q , b , n - s , s ) ; // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) sort1 ( q , off , k , s ) ; if ( ( s = d - c ) > 1 ) sort1 ( q , n - s , k , s ) ; }
Sorts the specified sub - array of integers into ascending order .