Commit 29203fda by BellCodeEditor

save project

parent 666d083a
Showing with 3 additions and 1 deletions
...@@ -9,7 +9,7 @@ num = random.choice(alist) ...@@ -9,7 +9,7 @@ num = random.choice(alist)
def binary_search(alist,num): def binary_search(alist,num):
low = 0 low = 0
high = len(alist) -1 high = len(alist) -1
while low < high: while low <= high:
mid = (low +high) //2 mid = (low +high) //2
gu = alist[mid] gu = alist[mid]
if gu == num: if gu == num:
...@@ -20,4 +20,5 @@ def binary_search(alist,num): ...@@ -20,4 +20,5 @@ def binary_search(alist,num):
high = mid -1 high = mid -1
else: else:
return None return None
print(num)
print(binary_search(alist,num)) print(binary_search(alist,num))
\ 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