选择排序算法
选择排序算法
# -*- coding: utf-8 -*-
# @Time : 2022/3/9 18:43
# @Author : chuqianyu
# @FileName: 012-选择排序.py
# @Software: PyCharm
# @Blog :https://home.cnblogs.com/u/chuqianyu
class Solution:
def selectSort(self, arr): # 选择排序
n = len(arr)
for i in range(n - 1, 0, -1):
for j in range(i):
temp = 0
if arr[j] > arr[i]:
temp = arr[j]
arr[j] = arr[i]
arr[i] = temp
return arr
if __name__ == "__main__":
arr = list(map(int, input().strip().split())) # "请输入数组长度,用空格隔开:"
s = Solution()
arr2 = s.selectSort(arr)
print(arr2)
for i in range(len(arr2)):
print(arr2[i], end=" ")
# print([0] * 2# 产生1行2列的列表
作者:楚千羽
出处:https://www.cnblogs.com/chuqianyu/
本文来自博客园,本文作者:楚千羽,转载请注明原文链接:https://www.cnblogs.com/chuqianyu/p/16247764.html
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利!