例如:
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]
例如:
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]