# encoding: utf:8l = [5, 6, 9, 11, 34, 66, 6, 8, 7 ]def twopointsearch (L): for i in range (Len (l)): min_index = i for J in range (I+1, len (L)): #### #循环判断得出依次次最小直的索引 if l[min_index] > l[j]: min_index = j l[i], l[min_index] = l[min_index], l[i] ### #l [i] Minimum value aa return la = twopointsearch (l) print (a) # # # # Bubble sort ' >>> list ' (range (10,0,-1)) [10, 9, 8, 7, 6, 5, 4, 3,  2, 1] "Def buBble_sort (L): for i in range (Len (l) -1,0,-1): for j in range (Len (L)-1): if l[j] > l[i]: l[i],l[j] = l[j],l[i] ###### l[i] stored in the cycle of judgment after the maximum straight, the first assignment is the last element return lb = bubble_sort (l) Print (b)
Output Result:
[5, 6, 6, 7, 8, 9, 11, 34, 66]
[5, 34, 6, 6, 7, 8, 9, 11, 66]
This article is from the "Sky Blue Star" blog, please be sure to keep this source http://jingkonglanxing.blog.51cto.com/1152128/1911575
Python insert sort and bubble sort