用户:
一起来编程吧ll查看:0 回复:2 评论:0 创建时间:2020-06-17T12:14:15
【作品展示】

【作品介绍】
选择排序算法
【作品源代码】
List_1 = [5, 4, 3, 2, 1]
List_2 = [9, 5, 4, 3, 2, 1, 6, 2]
# 选择排序算法
def selection_sort(List):
for j in range(len(List)):
index = j # 最小值的索引
for i in range(j+1, len(List)):
if List[i] < List[index]:
index = i
# 方法一
# temp = List.pop(index)
# List.insert(j, temp)
# 方法二
# temp = List[j]
# List[j] = List[index]
# List[index] = temp
List[j], List[index] = List[index], List[j]
return List
print(selection_sort(List_1))
print(selection_sort(List_2))
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn