Created
May 27, 2013 15:41
-
-
Save edumelzer/788540cc5e9b08e2e52f to your computer and use it in GitHub Desktop.
select_on_sort python (working)
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
print 'Digite os valores a serem ordenados separados por virgula:' | |
valores = [2,5,3,9,8] | |
def selection_sort(list): | |
l=list[:] # create a copy of the list | |
sorted=[] # this new list will hold the results | |
while len(l): # while there are elements to sort... | |
lowest=l[0] # create a variable to identify lowest | |
for x in l: # and check every item in the list... | |
if x<lowest: # to see if it might be lower. | |
lowest=x | |
sorted.append(lowest) # add the lowest one to the new list | |
l.remove(lowest) # and delete it from the old one | |
return sorted | |
print selection_sort(valores) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment