Commit 67d6c7fa by BellCodeEditor

auto save

parent b213652d
Showing with 10 additions and 4 deletions
import random import random
alist = range(1, 101) alist = [1,54,18,3,15,84,9,108]
num = random.choice(alist) num = random.choice(alist)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置 # 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
def search(num,_list): def search(num,_list_):
for i in range(0,len(_list_)):
for j in range(0,len(_list_)-i-1):
if _list_[j] > _list_[j+1]:
_list_[j],_list_[j+1] =_list_[j+1],_list_[j]
_list=_list_
print(_list)
low=0 low=0
high=len(_list)-1 high=len(_list)-1
while True: while True:
...@@ -19,4 +25,4 @@ def search(num,_list): ...@@ -19,4 +25,4 @@ def search(num,_list):
if not num in _list: if not num in _list:
return False return False
a=search(num,alist) a=search(num,alist)
print(a,num-1) print(a,num)
\ No newline at end of file \ 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