Commit 8c0bf47c by BellCodeEditor

save project

parent 5f7f53d9
Showing with 5 additions and 4 deletions
...@@ -9,13 +9,14 @@ num = random.choice(alist) ...@@ -9,13 +9,14 @@ num = random.choice(alist)
def binary_search(alist,num): def binary_search(alist,num):
while mi<mx: while mi<mx:
mid=(mi+mx)//2 mid=(mi+mx)//2
gis=num_list[mid] gis=alist[mid]
if num1==gis: if num1==gis:
print(mid)`7` return mid
break
elif mun>gis: elif mun>gis:
mi=mid+1 mi=mid+1
else: else:
mx=mid-1 mx=mid-1
return None return None
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
num1=20
mi=0
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