所以我正在写一个二进制搜索代码,这就是我所拥有的,但是我不知道出了什么问题,或者不知道它是否有效?
book = ["Archaeology", "Art", "Biology", "Chemistry", "Computing", "English", "French", "Geography", "History", "Maths", "Psychology"]
def binarySearch(book, find):
found = False
left = 0
right = len(book)-1
find = 'Geography'
while left <= right and not found:
midpoint = (right - left)//2
if book[midpoint] == find:
found = True
else:
if find < book[midpoint]:
right = midpoint - 1
else:
left = midpoint + 1
return found