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]
随风挥手 ——土木狗的IT生涯 | 群: 299524235 |