# 测试数据
l2 = [10, 2, 0, 35, 20, 8]
"""
冒泡排序
"""
def effervesce_sort(l_one: list):
for i in range(len(l_one) - 1):
for j in range(len(l_one) - 1 - i):
if l_one[j] > l_one[j + 1]:
# 判断两数位置是否正确, 交换顺序
l_one[j], l_one[j + 1] = l_one[j + 1], l_one[j]
return l_one
print(effervesce_sort(l2))
"""
选择排序
"""
def choice_sort(l_two: list):
for i in range(len(l_two)):
min_index = i # 定义一个最小索引用来保存最小值的索引
for j in range(i + 1, len(l_two)):
if l_two[min_index] > l_two[j]:
min_index = j
l_two[i], l_two[min_index] = l_two[min_index], l_two[i]
return l_two
print(choice_sort(l2))
欢迎查看我的技术文档
网站有我的联系方式,欢迎学习交流