008.冒泡法排序
2020-12-08 本文已影响0人
讲武德的年轻人
lst = [2,5,3,7,1,6,4]
for i in range(len(lst)):
for j in range(len(lst)-1-i):
if lst[j]>lst[j+1]:
temp = lst[j+1]
lst[j+1] = lst[j]
lst[j] = temp
print(lst)
lst = [2,5,3,7,1,6,4]
for i in range(len(lst)):
for j in range(len(lst)-1-i):
if lst[j]>lst[j+1]:
temp = lst[j+1]
lst[j+1] = lst[j]
lst[j] = temp
print(lst)