码迷,mamicode.com
首页 > 编程语言 > 详细

python selectsort

时间:2018-09-08 22:36:49      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:none   --   test   author   efault   int   cts   select   dex   

# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: test
Description :
Author : Administrator
date: 2018/9/2 0002
-------------------------------------------------
"""

# the default max number

# for i in range(1, len(s)):
# index = 0
# j = None
# for j in range(1, len(s) - i):
# if s[j] > s[index]:
# # 找出当前最大值的位置
# index = j
# temp = s[len(s) - i]
# s[len(s) - i] = s[index]
# s[index] = temp
s = [9, 1, 3, 10, 5]
for i in range(len(s) - 1):
index = i
j = 1
# 从剩下的中选出最小
for j in range(i + 1, len(s)):
if s[j] < s[index]:
# 找出当前最小值的位置
index = j
# temp = s[i]
# s[i] = s[index]
# s[index] = temp
s[i], s[index] = s[index], s[i]
print(s)

python selectsort

标签:none   --   test   author   efault   int   cts   select   dex   

原文地址:https://www.cnblogs.com/tnyleyon/p/9610419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!