python 实现冒泡排序

# encoding: utf-8
def bubble_sort(listScore):
    amount = len(listScore)
    while amount > 0:
        for i in range(amount - 1):
            if listScore[i] > listScore[i+1]:
                listScore[i] = listScore[i] + listScore[i+1]
                listScore[i+1] = listScore[i] - listScore[i+1]
                listScore[i] = listScore[i] - listScore[i+1]
        amount -= 1
    return listScore

score = [12,23,34,4,22,444]
ret = bubble_sort(score)
print(ret)
    

posted on 2019-02-28 19:49  念书头疼  阅读(256)  评论(0)    收藏  举报