Commit 38e5b36d by BellCodeEditor

auto save

parent 9140074b
Showing with 9 additions and 4 deletions
......@@ -6,8 +6,12 @@ for i in range(1, 101):
num = random.choice(alist)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
list1=[1,3,8,15,11,17,5,20,21,18]
for i in list1:
if
n=len(list1)
for i in range(0,n-1):
for j in range(0,n-1):
if list1[j]>list1[j+1]:
list1[j],list1[j+1]=list1[j+1],list1[j]
print(list1)
def binary_search(alist,num):
low=0
high=len(alist)-1
......@@ -21,6 +25,6 @@ def binary_search(alist,num):
high=mid-1
return None
a=binary_search(alist,num)
print(num)
a=binary_search(list1,17)
#print(num)
print(a)
\ 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