Package dsa

Class BinarySearch


  • public class BinarySearch
    extends Object
    This library implements binary search.
    • Constructor Detail

      • BinarySearch

        public BinarySearch()
    • Method Detail

      • indexOf

        public static int indexOf​(Comparable[] a,
                                  Comparable key)
        Returns the index of key in the sorted array a, or -1.
        Parameters:
        a - sorted array of comparable objects.
        key - search key.
        Returns:
        the index of key in the sorted array a, or -1.
      • indexOf

        public static int indexOf​(int[] a,
                                  int key)
        Returns the index of key in the array a, or -1.
        Parameters:
        a - array of objects.
        key - search key.
        Returns:
        the index of key in the array a, or -1.
      • indexOf

        public static int indexOf​(double[] a,
                                  double key)
        Returns the index of key in the array a, or -1.
        Parameters:
        a - array of objects.
        key - search key.
        Returns:
        the index of key in the array a, or -1.
      • main

        public static void main​(String[] args)
        Unit tests the library.
        Parameters:
        args - the command-line arguments.