您的位置:首页 > 编程语言 > Go语言

Sort Algorithm-->Select Sort

2016-07-24 23:38 537 查看
Each traversal find the minimal element start from 1 to n,than compare with the index of i,i+1…n-1,if smaller than swap them or next traversal

"""

select sort
language:python3.5
author:zhoutonglx

"""

#original unsorted list
L = [3,44,38,5,47,15,36,26,27,2,46,4,19,50,48]

def SelectSort(L):
length = len(L)
for i in range(length-1) :
for j in range(i+1,length) :
if L[i]>L[j] :
L[i],L[j] = L[j],L[i]  # like swap() in c++
print(L)

if __name__ == "__main__" :
SelectSort(L)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: