Commit 66c8154c by BellCodeEditor

save project

parent b097f043
Showing with 4 additions and 4 deletions
...@@ -8,14 +8,14 @@ num = random.choice(alist) ...@@ -8,14 +8,14 @@ num = random.choice(alist)
def binary_search(alist,num): def binary_search(alist,num):
low = 0 low = 0
high = len(num_list)-1 high = len(alist)-1
while low <= high: while low <= high:
mid = (low+high) // 2 mid = (low+high) // 2
guess_num = num_list[mid] guess= alist[mid]
if guess_num == bingo_num: if guess== num:
print('找到了','它的索引是',mid) print('找到了','它的索引是',mid)
break break
elif guess_num < bingo_num: elif guess < num:
low = mid+1 low = mid+1
else: else:
high = mid-1 high = mid-1
......
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