python-冒泡排序

例如:

data=[2,56,24,2,45,12,33,11,47,58,10,25,55,]
for i in range(1,len(data)):
for j in range(len(data)-i):
if data[j] > data[j+1]:
data[j],data[j+1] = data[j+1],data[j]
print(data)

结果:

[2, 2, 10, 11, 12, 24, 25, 33, 45, 47, 55, 56, 58]

posted on 2017-01-13 10:12  舞曲  阅读(119)  评论(0编辑  收藏  举报

导航