1. 程式人生 > >Sort Algorithm-->Select Sort

Sort Algorithm-->Select Sort

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)