1、冒泡排序

#Author: Caesars
l = [12,65,67,21,3,9,50,24]
for i in range(len(l)):
    for j in range(len(l)-i-1):
        if l[j] > l[j+1]:
            a = l[j]
            l[j] = l[j+1]
            l[j+1] = a
            print(l)

2、选择排序

#Author: Caesars
l = [12,65,67,21,3,9,50,24,10]
for i in range(len(l)):
    minindex = i
    for j in range(i+1,len(l)):
        if(l[j] < l[minindex]):
            minindex = j
    l[i],l[minindex] = l[minindex],l[i]
    print(l)

 

posted on 2020-06-22 15:26  天王落尘之haohao  阅读(123)  评论(0编辑  收藏  举报