二分查找算法Python3实现

def binarysearch(list,item):
    low=0
    high=len(list)-1
    while low<=high:
        mid=int((low+high)/2)
        guess=list[mid]
        if guess==item:
            return mid
        if guess>item:
            high=mid-1
        else :
            low=mid+1
    return None mylist=[1,3,5,7,9,11,13,15,17,19,21]
B=binarysearch(mylist,15)
print(B)
    原文作者:查找算法
    原文地址: https://blog.csdn.net/beidaxiaozhang/article/details/78523718
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞