Class BinarySearch


  • public class BinarySearch
    extends Object
    Binary search in bottom-up sorted integer arrays.
    Author:
    Tilman Neumann
    • Constructor Detail

      • BinarySearch

        public BinarySearch()
    • Method Detail

      • getInsertPosition

        public int getInsertPosition​(int[] array,
                                     int maxIndex,
                                     int x)
        Find the insert position for x into array given that array is sorted bottom-up. More precisely: If array[maxIndex-1] > x, return the index of the first entry of array[0].. array[maxIndex-1] greater than x. If array[maxIndex-1] <= x, return maxIndex.
        Parameters:
        array -
        maxIndex - the maximum index to consider, exclusive (may be smaller than the array size)
        x -
        Returns:
        the insert position
      • main

        public static void main​(String[] args)