标签:
/** * * 二分查找算法 * * * * @param srcArray 有序数组 * * @param target 查找元素 * * @return srcArray数组下标,没找到返回-1 */ public int binarySearch(int[] srcArray, int target){ int left = 0; int right = srcArray.length - 1; while(left <= right) { int mid = (left + right)/2; if(srcArray[mid] == target) { return mid; } else if(srcArray[mid] > target) { right = mid - 1; } else { left = mid + 1; } } return -1; }
标签:
原文地址:http://www.cnblogs.com/lasclocker/p/4540800.html