Created
November 28, 2011 13:17
-
-
Save mahmoudhossam/1400370 to your computer and use it in GitHub Desktop.
A python implementation of the selection sort algorithm
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
''' | |
Created on Nov 26, 2011 | |
@author: Mahmoud | |
''' | |
def sort(seq): | |
pos = 0 | |
length = len(seq) | |
for i in seq: | |
unsorted = seq[pos:length] | |
smallest = minimum(unsorted) | |
seq.remove(smallest) | |
seq.insert(pos, smallest) | |
pos += 1 | |
return seq | |
def minimum(seq): | |
value = seq[0] | |
for i in seq: | |
if i < value: | |
value = i | |
return value | |
def main(): | |
print sort([5, 10, 2, 9, 0, 3]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment