该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
看了Java api,看得那个相当蛋痛。。。 相当傻蛋痛。。。。。
public static int binarySearch(int[] a,
int key)
Searches the specified array of ints for the specified value using the binary search algorithm. The array must be sorted (as by the sort(int[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.
Parameters:
a - the array to be searched
key - the value to be searched for
//请高手重点讲解下面的返回值?? (-(insertion point) - 1). 这个是啥玩意???
Returns:
index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.