Commit 6485bd9f by BellCodeEditor

save project

parent abfa3604
Showing with 7 additions and 9 deletions
...@@ -11,15 +11,13 @@ def binary_search(alist,num): ...@@ -11,15 +11,13 @@ def binary_search(alist,num):
high=len(alist)-1 high=len(alist)-1
while low<=high: while low<=high:
mid=(low+high)//2 mid=(low+high)//2
guess=num_list[mid] guess=alist[mid]
if guess == num: if guess == num:
print("找到了") return mid
break
elif guess < num: elif guess < num:
low = mid + 1 low = mid + 1
else: else:
high = mid-1 high = mid-1
if low>high: if low>high:
print("该数不存在") return None
break print(binary_search(alist,num ))
binary_search(alist,num ) \ No newline at end of file
\ 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