类 BinarySearch
- java.lang.Object
-
- edu.princeton.cs.algs4.BinarySearch
-
public class BinarySearch extends java.lang.ObjectTheBinarySearchclass provides a static method for binary searching for an integer in a sorted array of integers.The indexOf operations takes logarithmic time in the worst case.
For additional documentation, see Section 1.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
方法概要
修饰符和类型 方法 说明 static intindexOf(int[] a, int key)Returns the index of the specified key in the specified array.static voidmain(java.lang.String[] args)Reads in a sequence of integers from the whitelist file, specified as a command-line argument; reads in integers from standard input; prints to standard output those integers that do not appear in the file.static intrank(int key, int[] a)已过时。Replaced byindexOf(int[], int).
-
-
-
方法详细资料
-
indexOf
public static int indexOf(int[] a, int key)Returns the index of the specified key in the specified array.- 参数:
a- the array of integers, must be sorted in ascending orderkey- the search key- 返回:
- index of key in array
aif present;-1otherwise
-
rank
@Deprecated public static int rank(int key, int[] a)已过时。Replaced byindexOf(int[], int).Returns the index of the specified key in the specified array. This function is poorly named because it does not give the rank if the array has duplicate keys or if the key is not in the array.- 参数:
key- the search keya- the array of integers, must be sorted in ascending order- 返回:
- index of key in array
aif present;-1otherwise
-
main
public static void main(java.lang.String[] args)
Reads in a sequence of integers from the whitelist file, specified as a command-line argument; reads in integers from standard input; prints to standard output those integers that do not appear in the file.- 参数:
args- the command-line arguments
-
-