Python 排序 冒泡排序

# -*- coding: utf-8 -*-
# author: zhonghua
# filename: sort_bubble.py
# create: 2016/3/28
# version: 1.0

# 冒泡排序

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

if __name__ ==  '__main__':
    lst = [19, 28, 30, 5, 8, 28, 60]
    bubble(lst)
    for i in lst:
        print i

你可能感兴趣的:(Python 排序 冒泡排序)