python - 冒泡排序

tech2024-12-07  6

def bubble_sort(lists): def swap(i, j): lists[i], lists[j] = lists[j], lists[i] for i in range(len(lists) - 1): for j in range(len(lists) - i -1): if lists[j] > lists[j + 1]: swap(j, j + 1) return lists bubble_sort([1, 3, 4, 2, 9, 8, 7, 6, 5, 0, 99, 78])

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 78, 99]

最新回复(0)