Commit 35857d0a by BellCodeEditor

auto save

parent 01960a82
Showing with 21 additions and 11 deletions
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
abc(num_list,11)
\ No newline at end of file
# 使a=9用二分查找法,找出9和20在列表里面的索引 # 使a=9用二分查找法,找出9和20在列表里面的索引
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21] num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
a=9 a=20
b=20 b=20
lou=0
high=len(num_list)-1
mid=(lou+high)//2 def abc(alist,num):
if num_list[mid]==a: lou=0
print("找到了!") high=len(num_list)-1
elif num_list[mid]<a: while lou <= high:
lou=mid+1
else: mid=(lou+high)//2
high=mid-1 if alist[mid]==num:
\ No newline at end of file print("找到了!")
exit()
elif alist[mid]<num:
lou=mid+1
else:
high=mid-1
abc(num_list,11)
\ 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