Package dsa
Class BinarySearch
- java.lang.Object
-
- dsa.BinarySearch
-
public class BinarySearch extends Object
This library implements binary search.
-
-
Constructor Summary
Constructors Constructor Description BinarySearch()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
indexOf(double[] a, double key)
Returns the index ofkey
in the arraya
, or -1.static int
indexOf(int[] a, int key)
Returns the index ofkey
in the arraya
, or -1.static int
indexOf(Comparable[] a, Comparable key)
Returns the index ofkey
in the sorted arraya
, or -1.static void
main(String[] args)
Unit tests the library.
-
-
-
Method Detail
-
indexOf
public static int indexOf(Comparable[] a, Comparable key)
Returns the index ofkey
in the sorted arraya
, or -1.- Parameters:
a
- sorted array of comparable objects.key
- search key.- Returns:
- the index of
key
in the sorted arraya
, or -1.
-
indexOf
public static int indexOf(int[] a, int key)
Returns the index ofkey
in the arraya
, or -1.- Parameters:
a
- array of objects.key
- search key.- Returns:
- the index of
key
in the arraya
, or -1.
-
indexOf
public static int indexOf(double[] a, double key)
Returns the index ofkey
in the arraya
, or -1.- Parameters:
a
- array of objects.key
- search key.- Returns:
- the index of
key
in the arraya
, or -1.
-
main
public static void main(String[] args)
Unit tests the library.- Parameters:
args
- the command-line arguments.
-
-