#1.先来sort方法排序
lst = [3,2,9,4,34,43,22,11]
lst.sort(reverse=False)
#2.定义一个列表,将原列表的最小值取出来,依次添加
lst1 = []
def sort_list():
try:
for i in range(len(lst)):
lst1.append(min(lst))
lst.remove(min(lst))
except ValueError as e:
pass
finally:
return lst1
print(sort_list())
#3.和方法二类似,只是更简单,效率更高,用递归
def get_min():
lst1.append(min(lst))
lst.remove(min(lst))
if len(lst)>0:
get_min()
return lst1
print(get_min())
#4.最后就是冒泡排序啦..
def bubble_sort():
for i in range(len(lst)):
for j in range(len(lst)-i-1):
if lst[j]>lst[j+1]:
lst[j], lst[j + 1] = lst[j+1],lst[j]
return lst
print(bubble_sort())