Commit 376a4ae0 by BellCodeEditor

save project

parent 8f8280f2
Showing with 66 additions and 13 deletions
a=17# 使用二分查找法,找出9和20在列表里面的索引 # a=17# 使用二分查找法,找出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]
low=0 num_list=[]
high=len(num_list)--1 for i in range(101):
def w(an): num_list.append(i)
while low <= high: num= random.randint(0,100)
mid=(low+high)//2 u=0
g=num_list[mid] o=len(num_list)
if g == a: p=(u+o)//2
print("找到了",a) def v(li,n)
while u <= o:
y=p
if y==num:
print(p)
break break
elif g < a: elif y<num:
low =mid+1 o=y-1
else: else:
high=mid-1 u=y+1
print(v(num_list,num))
def w(list,f):
low=0
high=len(num_list)-1
while low <= high:
mid=(low+high)//2
g=list[mid]
if g == f:
# print("找到了",a)
return f
elif g < f:
low =mid+1
else:
high=mid-1
print(w(num_list,a))
......
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