list = [1,2,4,6,12,34,42,56,66,73,85] key = 4 center = int(len(list)/2) if key in list: while True: if list[center] > key: center = center - 1 elif list[center] < key: center = center + 1 elif list[center] == key: print("要找的数字是%d索引是%d"%(key,center)) break
Python——二分法
最新推荐文章于 2024-02-22 17:07:46 发布