Commit 7d16dfd8 by BellCodeEditor

save project

parent 356882fb
Showing with 14 additions and 12 deletions
......@@ -2,19 +2,21 @@
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
high=len(num_list)-1
low=0
mid=(high+low)//2
n=20
n=2
while True:
if num_list[mid]<n:
low=mid+1
while low <= high:
mid = (low+high)//2
guess = num_list[mid]
if guess==n:
print('找到'+str(n)+'了,索引为'+str(mid))
break
elif num_list[mid]>n:
elif guess>n:
high=mid-1
elif num_list[mid]==n:
print('找到'+str(n)+'了,索引为'+'str(mid)')
break
elif high<=low:
print('找不到'+'n'+',嘿嘿嘿~')
break
elif guess<n:
low = mid +1
if high<low:
print('找不到')
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