查找算法

二分查找

func BinarySearch(data []int, key int) int {
	var low, high, mid int

	low = 0
	high = len(data) - 1

	for low <= high {
		mid = (low + high) / 2

		if key < data[mid] {
			high = mid - 1
		} else if key > data[mid] {
			low = mid + 1
		} else {
			return mid
		}
	}

	return -1
}