Commit 1e64d827 by BellCodeEditor

save project

parent 796ce352
Showing with 16 additions and 14 deletions
a=[1,3,5,8,11,15,17,18,20,21]
low=0
h=len(a)-1
shu=1 #找的数
while low<=h:
mid = (low+h)//2
g=a[mid]
if g==shu:
print("找到了",mid)
break
elif g <shu:
low = mid+1
elif g>shu:
h = mid-1
\ No newline at end of file
def erfen(alist,num):
low=0
h=len(alist)-1
while low<=h:
mid = (low+h)//2
g=alist[mid]
if g==num:
print("找到了",mid)
break
elif g <num:
low = mid+1
elif g>num:
h = mid-1
erfen(a,15)
\ 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