#冒泡lst = [13,124,42543,3,6,3,63,637,5,747,758,58,231,23,414,53,64,6]for a in range(len(lst)): i = 0 while i < len(lst)-1: if lst[i] > lst[i + 1]: lst[i], lst[i+1] = lst[i+1], lst[i] i += 1print(lst)#二分法n = 61r = len(lst) -1l = 0count = 0while l <= r: m = (l + r) // 2 if n > lst[m]: l = m + 1 elif n < lst[m]: r = m - 1 else: print(count) print("找到了") print(m) break count += 1else: print("不存在")
转载于:https://www.cnblogs.com/sun-ming-ji/p/9342373.html
相关资源:java 冒泡算法和插入法排序,二分法查找