二分查找

def bin_search(data, value):
    low = 0
    hight = len(data) - 1
    while low <= hight:
        mid = (low+hight) // 2
        if data[mid] == value:
            return mid
        elif data[mid] > value:
            hight = mid - 1
        else:
            low = mid + 1

print(bin_search([2,1,8,3,6,9],6))
posted @ 2018-11-08 12:15  桥前石头  阅读(85)  评论(0编辑  收藏  举报