Commit 4749599f by BellCodeEditor

save project

parent b250abfe
Showing with 18 additions and 3 deletions
# 使用二分查找法,找出9和20在列表里面的索引
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
\ No newline at end of file
l = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
def find(d,a,b):
c = (a+b)//2
if l[c] == d:
print('找到了')
return
elif l[c] < d:
a = c+1
find(d,a,b)
elif l[c] < d:
b = c-1
find(d,a,b)
else:
print('查无此数')
return
find(10,0,9)
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