Created
February 8, 2013 16:48
-
-
Save mahmoudhossam/4740255 to your computer and use it in GitHub Desktop.
Insertion sort in Python.
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 insertion_sort(seq): | |
j = 1 | |
for i in range(1, len(seq)): | |
j = i | |
while j > 0 and seq[j] < seq[j-1]: | |
seq[j], seq[j-1] = seq[j-1], seq[j] | |
j -= 1 | |
return seq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment