Created
September 11, 2012 14:20
-
-
Save felipernb/3698965 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(a): | |
| for i in xrange(1, len(a)): | |
| n = a[i] | |
| pos = i | |
| while pos > 0 and a[pos-1] > n: | |
| a[pos] = a[pos-1] | |
| pos -= 1 | |
| a[pos] = n | |
| return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment