二分法查找 时间复杂度为O(logn)
public class BiSearch { public static int search(int[] data, int find){int low = 0;
int mid = 0;
int upper = 0;if (null == data) {return -1;}
upper = data.length - 1;while (low <= upper) {mid = (low + upper)/2;if (data[mid] > find) {upper = mid - 1;}else if (data[mid] < find) {low = mid + 1;}else {return mid;}}return -1;}public static void main(String[] args) { int[] nums = { 55, 7, 28, -3, 1, 7, 29, 0, 5, 4 }; Bisearch.sort(nums, 10); }
}