Loading

python冒泡排序

# 冒泡排序

numbers = [1, 3, 4, 54, 5, 6, 92, 2]


def bubbling_sort(array):
    for x in range(len(array)):
        for y in range(len(array) - 1):
            if array[y] > array[y + 1]:
                array[y], array[y + 1] = array[y + 1], array[y]
    return array


if __name__ == '__main__':
    print(bubbling_sort(numbers))

# OUTPUT

[1, 2, 3, 4, 5, 6, 54, 92]
posted @ 2021-05-16 22:17  随风挥手  阅读(140)  评论(0编辑  收藏  举报
群1
299524235(满)
群2
362812191