思想:从后往前冒泡,轻的在前面,重的在后面
score=[100,98,67,87,0,20,76,10,66,77]
n=len(score)
for i in range(0,n-1):
for j in range(n-1,i,-1):
if score[j] < score[j-1]:
score[j],score[j-1]=score[j-1],score[j]
print('排序后:',score)
执行后的结果:
排序后: [0, 10, 20, 66, 67, 76, 77, 87, 98, 100]