Commit c58ccc3d by BellCodeEditor

save project

parent 4cab9573
Showing with 17 additions and 3 deletions
# 使用二分查找法,找出9和20在列表里面的索引
c=11
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
a=0
b=0
c=((a+b)//2)
b=len(num_list)-1
d=0
e=0
while a<=b:
d=(a+b)//2
e=num_list[d]
if e==c:
print("找到了,它在列表里的索引是:",d)
break
elif e<c:
a=d+1
elif e>c:
b=d-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