1.升序排序,由小到大
lst = [1,4,234,1,31,132,323,13,123,1,8,967,24,486,23,1,44,7,56]
for i in range(len(lst)-1): # 记录排的次数
count = 0
while count < len(lst)-1: # 排序
if lst[count] > lst[count+1]: # 判断两端的大小
lst[count],lst[count+1] = lst[count+1],lst[count]
count = count + 1
print(lst)
- 降序排序,由大到小
lst = [1,4,234,1,31,132,323,13,123,1,8,967,24,486,23,1,44,7,56]
for i in range(len(lst)-1):
count = 0
while count < len(lst)-1:
if lst[count] < lst[count+1]:
lst[count],lst[count+1] = lst[count+1],lst[count]
count = count + 1
print(lst)