python实现冒泡排序的简单示例

def main():
    array = [2,1,5,3,4,6]
    for i in range(len(array)):
        for j in range(i):
            if array[j] > array[j+1]:
                array[j],array[j+1] = array[j+1],array[j]
    print array
if __name__ == '__main__':
    main()


打印结果:[1, 2, 3, 4, 5, 6]

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