已知一个按升序排列的列表ls 使用二分法在该列表中查找某数字。现用递归函数实现该功能 请完成填
已知一个按升序排列的列表ls,使用二分法在该列表中查找某数字。现用递归函数实现该功能,请完成填空。 def binary_search(ls, target): if 空1 : print("未找到") return midIndex = len(ls) // 2 if target <ls[midIndex]: 空2 elif target > ls[midIndex] : 空3 else: print("找到了,位置为"+str(midIndex)) ls = [2,8,10,18,25,30,36,40,50,88] #升序排列 num = eval(input("请输入要查找的数:")) binary_search(ls, num) 在空白处可以填入的正确选项是()。 知识点:递归函数
A.len(ls)==0 binary_search(ls[ :midIndex], target) binary_search(ls[midIndex+1: ], target)
B.not ls binary_search(ls[ :midIndex], target) binary_search(ls[midIndex+1: ], target)
C.len(ls)==0 binary_search(ls[midIndex+1: ], target) binary_search(ls[ :midIndex], target)
D.ls==[] binary_search(ls[midIndex+1: ], target) binary_search(ls[ :midIndex], target)

回答
共1条回复-
len(ls)==0 binary_search(ls[ :midIndex], target) binary_search(ls[midIndex+1: ], target);not ls binary_search(ls[ :midIndex], target) binary_search(ls[midIndex+1: ], target)
