def BinarySearch(arr, left, right, key):
while left <= right:
mid = left + (right - left) // 2
if arr[mid] == key:
return True # 元素存在,返回True
if arr[mid] < key:
left = mid + 1
else:
right = mid - 1
return False # 元素不存在,返回False
def main():
arr = [6, 17, 25, 34, 52, 63, 85]
n = len(arr)
key = 6
result = BinarySearch(arr, 0, n - 1, key)
if result:
print("元素{}存在".format(key))
else:
print("元素{}不存在".format(key))
if __name__ == "__main__":
main()