选择排序算法
作者:互联网
选择排序算法
# -*- 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列的列表
标签:__,arr,temp,选择,算法,arr2,print,排序 来源: https://www.cnblogs.com/chuqianyu/p/16247764.html