冒泡排序

def bubble(li):
    tag = 0
    for i in range(len(li)-1): 
        for j in range(len(li)-i-1):
            if li[j] > li[j+1]:
                li[j], li[j+1] = li[j+1],li[j]
                tag = 1        
        if tag == 0:
        return
    print(li)


li=[2,3,4,5,6,7,8,9,0,1]


bubble(li)
posted @ 2017-03-09 18:04  Dus  阅读(136)  评论(0编辑  收藏  举报