def bina_search(alist,a):
low=0
high=len(alist)-1
while(low<=high):
mid=(low+high)//2
if(alist[mid]>a):
high=mid-1
elif(alist[mid]<a):
low=mid+1
else:
return mid
return -1
alist=[1,2,4,4,10]
a=8
print(bina_search(alist,a))
【Python】用python实现二分检索
最新推荐文章于 2024-02-22 17:07:46 发布