排序
1 # 排序 2 li = [12,1,45,23,78,34,90,32] 3 n = len(li) 4 print(li) 5 # 遍历所有元素 6 for i in range(n): 7 for j in range(i+1, n): 8 if li[i] > li[j]: 9 li[i], li[j] = li[j], li[i] 10 print(li) 11 ''' 12 [12,1,45,23,78,34,90,32] 13 i = 0 j=[1,7] 14 i=0 j=1 1 12 45,23,78,34,90,32 15 i=0 j=2 1 12 45,23,78,34,90,32 16 i=0 j=7 1 12 45,23,78,34,90,32 17 i=1 j=[2,7] 18 i=1 j=2 1 12 45,23,78,34,90,32 19 i=1 j=7 1 12 45,23,78,34,90,32 20 i=2 j=[3,7] 21 i=2 j=3 1 12 23 ,45,78,34,90,32 22 i=2 j=7 1 12 23 ,45,78,34,90,32 23 i=3 j=[4,7] 24 i=3 j=4 1 12 23 ,45,78,34,90,32 25 i=3 j=5 1 12 23 ,34,78,45,90,32 26 i=3 j=6 1 12 23 ,34,78,45,90,32 27 i=3 j=7 1 12 23 ,32,78,45,90,34 28 29 i=4 j=[5,7] 30 i=4 j=5..... 31 32 33 '''