查找算法

	/**
	 * 二分法查找 
	 * 查找线性表必须是有序列表
	 * 
	 * @param e
	 * @param key
	 * @return
	 */
	public int binarySearch(int[] e, int key) {
		int low = 0, high = e.length - 1, mid;
		while (low <= high) {
			mid = (low + high) / 2;
			if (key == e[mid]) {
				return mid;
			} else if (key < e[mid]) {
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
		return -1;
	}

你可能感兴趣的:(java,算法)