Commit a59cf310 by BellCodeEditor

save project

parent 3c2a3c74
Showing with 24 additions and 0 deletions
alist=[input('给我输列表!')]
num=input('你想找几?必须在列表里!')
n=len(alist)
for i in range(0,n-1):
for j in range(0,n-1):
if alist[j]<alist[j+1]:
alist[j],alist[j+1]=alist[j+1],alist[j]
def binary_search(alist,num):
low=0
high=len(alist)-1
while low<=high:
mid=(low+high)//2
guess=alist[mid]
if guess==num:
return mid
elif guess<num:
low=mid+1
else:
high=mid-1
return None
re=binary_search(alist,num)
print("The number that gives is",num)
print("它在列表里的索引是:",re)
\ 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