Commit d57c55b4 by BellCodeEditor

save project

parent efc5944e
Showing with 7 additions and 9 deletions
......@@ -9,17 +9,15 @@ num = random.choice(alist)
def binary_search(alist,num):
low = 0
high = len(alist)-1
while low<=high:
mid = (low+high)//2
guess = alist[mid]
if guess == num:
print("找到了,索引是",mid)
break
return mid
elif guess<num:
low+=1
elif guess>num:
high-=1
low=mid+1
else:
print('没有')
binary_search(alist,num)
\ No newline at end of file
high = mid-1
return None
a = binary_search(alist,num)
print(a)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment