1、冒泡排序
#Author: Caesars l = [12,65,67,21,3,9,50,24] for i in range(len(l)): for j in range(len(l)-i-1): if l[j] > l[j+1]: a = l[j] l[j] = l[j+1] l[j+1] = a print(l)
2、选择排序
#Author: Caesars l = [12,65,67,21,3,9,50,24,10] for i in range(len(l)): minindex = i for j in range(i+1,len(l)): if(l[j] < l[minindex]): minindex = j l[i],l[minindex] = l[minindex],l[i] print(l)