python冒泡排序

def bubble(a):
    n = len(a)
    for i in range(1,n):
        for j in range(0,n-i):
            if a[j] > a[j+1]:
                a[j],a[j+1] = a[j+1],a[j]

if __name__ == '__main__':
    lst = [6,5,4,3,2,1]
    bubble(lst)
    print(lst)

posted @ 2021-08-18 09:52  brady-wang  阅读(30)  评论(0编辑  收藏  举报