public static int search ( short [ ] shortArray , short value ) { int start = 0 ; int end = shortArray . length - 1 ; int middle = 0 ; while ( start <= end ) { middle = ( start + end ) >> 1 ; if ( value == shortArray [ middle ] ) { return middle ; } if ( value < shortArray [ middle ] ) { end = middle - 1 ; } else { start = middle + 1 ; } } return - 1 ; }
Search for the value in the sorted short array and return the index .