Skip to content

Instantly share code, notes, and snippets.

@mahmoudhossam
Created November 28, 2011 13:17
Show Gist options
  • Save mahmoudhossam/1400370 to your computer and use it in GitHub Desktop.
Save mahmoudhossam/1400370 to your computer and use it in GitHub Desktop.
A python implementation of the selection sort algorithm
'''
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