Commit a68c46d7 by BellCodeEditor

save project

parent 987b6690
Showing with 14 additions and 11 deletions
......@@ -7,14 +7,17 @@ num = random.choice(alist)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
def binary_search(alist,num):
high=len(alist)-1
low=0
while low <= high:
=(+)//2
=
if num== :
print("找到了,索引是",)
exit()
elif < :
=-1
else:
=+1
print("没有这个数")
\ No newline at end of file
mid=(low+high)//2
zjz=num_list[mid]
if mum == zjz:
print("找到了,索引是",mid)
exit()
elif cz < zjz:
high=mid-1
else:
low=mid+1
print("没有这个数")
\ 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