Commit 9a3fb931 by BellCodeEditor

auto save

parent adaf6f8a
Showing with 31 additions and 0 deletions
# 使用二分查找法,找出9和20在列表里面的索引
def binarySearch(alist,bingoNum):
low = 0
high = len(alist)-1
while high > low:
mid = (low + high)//2
num = alist[mid]
if bingoNum == num:
return mid
elif num > bingoNum:
high = mid-1
else:
low = mid+1
return None
num_list = [5435,423,432,3,43,5,66,547,76,64,654,676,8,565,32,45,4356,778,56,645,6,345,4,55,54]
num_list.sort()
print(num_list)
while True:
guess =input("请输入需要查找的数:")
if guess == "q":
break
else:
guess = int(guess)
print(binarySearch(num_list,guess))
print(binarySearch(num_list,guess))
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