Commit 376a4ae0 by BellCodeEditor

save project

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