public static int binarySearch ( Quicksortable qs , int size ) { int low = 0 ; int high = size - 1 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; int cmp = qs . compare ( mid , - 1 ) ; if ( cmp < 0 ) low = mid + 1 ; else if ( cmp > 0 ) high = mid - 1 ; else return mid ; // key found } return - ( low + 1 ) ; // key not found. }
the compare function on Quicksortable will always pass - 1 as the second index swap function is never called