private void sort ( final T [ ] array , int start , int end , Comparator < T > lt ) { if ( start == end ) return ; if ( ( end - start ) <= 15 ) this . selectionSort ( array , start , end , lt ) ; else { final T pivot = array [ start + ( ( end - start ) / 2 ) ] ; T tmp ; int i = start - 1 ; int j = end ; while ( true ) { do i ++ ; while ( lt . compare ( array [ i ] , pivot ) < 0 ) ; do j -- ; while ( lt . compare ( pivot , array [ j ] ) < 0 ) ; if ( i >= j ) break ; tmp = array [ i ] ; array [ i ] = array [ j ] ; array [ j ] = tmp ; } this . sort ( array , start , i , lt ) ; this . sort ( array , i , end , lt ) ; } }
Merge sort implementation for a given array .