我正在尝试创建我的二进制搜索的递归版本的实现。这就是我到目前为止所拥有的。任何人都可以帮助我不知道如何完成。
def binarySearch(searchList, numberSought, low, high):
if high < low:
return False
midpoint = (low + high)//2
print ("high is index", high)
print ("low is index", low)
print ("midpoint is index", midpoint)
if searchList[midpoint] == numberSought:
return True
elif ...
else:
...
mylist = [2, 4, 7, 13, 21, 22, 27, 31, 41, 77, 97, 144, 168]
first = 0
last = len(mylist) - 1
candidate = int(input("Does our list contain the following number? "))
print ("It is ",binarySearch(mylist,candidate,first,last), "that our list contains", candidate)