python-递归-二分法

二分法

data_list = [2,3,5,6,8,34,45,56,3432,23423,234234,23423423,234234234]
def b_search(dataFind, low, high, dataList):
    mid = int((low + high)/2)
    if low == high:
        print('not found')
        return False
    elif dataList[mid] > dataFind:
        b_search(dataFind, low, mid-1, dataList)
    elif dataList[mid] < dataFind:
        b_search(dataFind, mid+1, high, dataList)
    else:
        print('found')
b_search(45,0,len(data_list),data_list)

你可能感兴趣的:(python-递归-二分法)