def _dichotomy_search2(key, a, lo, hi):
if hi < lo:
return -1
mid = (lo + hi) // 2
if a[mid] > key:
return self._dichotomy_search2(key, a, lo, mid)
elif a[mid] < key:
return self._dichotomy_search2(key, a, mid + 1, hi)
else:
return mid
def __dichotomy_search(key, a):
return self._dichotomy_search2(key, a, 0, len(a))
__dichotomy_search(10, [1, 9, 10, 36, 89, 101, 500, 1500])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)