Python 冒泡排序
1 #!/usr/bin/env python 2 #-*- coding:utf-8 -*- 3 data = [10,4,33,21,54,3,8,11,5,22,2,1,17,13,6] 4 5 for j in range(1,len(data)): 6 for i in range(len(data)-j): 7 if data[i] > data[i+1]: 8 tmp = data[i+1] 9 data[i+1] = data[i] 10 data[i] = tmp 11 print(data)
[1, 2, 3, 4, 5, 6, 8, 10, 11, 13, 17, 21, 22, 33, 54]