Created
July 4, 2016 03:19
-
-
Save xiaotangyuan/2480514868b3e9a332cb55af9f654523 to your computer and use it in GitHub Desktop.
选择排序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selectorder(thelist): | |
for index,num in enumerate(thelist): | |
minnum = num | |
minnum_index = index | |
for index2,num2 in enumerate(thelist[index+1:]): | |
if num2 < minnum: | |
minnum = num2 | |
minnum_index = index + index2 + 1 | |
thelist[index] = minnum | |
thelist[minnum_index] = num | |
return thelist | |
if __name__ == '__main__': | |
thelist = [9,1,4,2,9,5,3,1,98,46] | |
res = selectorder(thelist) | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment