Commit 2ad74231 by BellCodeEditor

save project

parent b3a070e7
Showing with 10 additions and 5 deletions
...@@ -3,11 +3,13 @@ num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21] ...@@ -3,11 +3,13 @@ num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
low=0 low=0
high=len(num_list)-1 high=len(num_list)-1
def b_s(alist,num):
while low<=high: low=0
guess=20 high=len(alist)-1
mid=(low+high)//2 while low<=high:
num=num_list[mid] guess=alist[mid]
mid=(low+high)//2
num=alist[mid]
if guess==num: if guess==num:
print('找到了',mid) print('找到了',mid)
break break
...@@ -16,3 +18,5 @@ while low<=high: ...@@ -16,3 +18,5 @@ while low<=high:
else: else:
low=mid+1 low=mid+1
r=b_s(num_list,21)
print(r)
\ 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