天天看點

選擇排序python實作

'''
Created on 2017-1-6

@author: admin
'''
def selectSort(source):
    for i in range(len(source)):
        mins=source[i]
        index=i
        for j in range(i,len(source)):
            if(mins>source[j]):
                mins=source[j]
                index=j
        tmp=source[i]
        source[i]=mins
        source[index]=tmp

if __name__ == '__main__':
    source=[9,1,8,7,4,5,2,6,11]
    selectSort(source)
    for i in range(len(source)):
        print(source[i],end=",")      

繼續閱讀