L = [i for i in range(1, 102)] jude = 20 L1 = [5,4,2,5,9,6,3,2,5,4,1,2,5] // 二分法 def erfen(L, jude): t = len(L)//2 t_start = 0 t_end = len(L) - 1 while t_start <= t_end and L[t] != jude: if L[t] < jude: t_start = t + 1 if L[t] > jude: t_end = t - 1 t = (t_start + t_end)//2 print(t_start,t_end,t,L[t]) print(t,L[t]) // 选择排序 def choose(L): count = len(L) for i in range(count): temp = 0 res = 0 for j in range(i, count): if temp < L[j]: temp = L[j] res = j L[i], L[res] = temp, L[i] return L
python 二分排序和选择排序
最新推荐文章于 2024-08-10 17:46:21 发布