氣泡排序 插入排序 快排

tslam發表於2024-03-29
l1 = [11, 55, 0, 88, 22, 77, 44, 44, 66]

# 氣泡排序
# for k in range(len(l1) - 1): # n-1輪冒泡
# for i in range(len(l1) - 1 - k):
# x = l1[i]
# y = l1[i + 1]
# if x > y:
# l1[i], l1[i + 1] = y, x
#
# print(f'l1:{l1}')


# 插入排序
# for i in range(1, len(l1)):
# while i - 1 >= 0 and l1[i] < l1[i - 1]:
# l1[i], l1[i - 1] = l1[i - 1], l1[i]
# i -= 1
# print(f'l1:{l1}')

相關文章