Last active
August 10, 2017 17:08
-
-
Save MorrisLaw/575d0f59ed4e8415869545f25e5300f1 to your computer and use it in GitHub Desktop.
Insertion sort, ascending order based off of the pseudocode in Introduction to Algorithms by C.L.R.S.
This file contains 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
A = [10,2,5,7,3,22] | |
for j in xrange(1, len(A)): | |
key = A[j] | |
# Insert A[j] into the sorted sequence A[1..j-1]. | |
i = j - 1 | |
while (i > -1 and A[i] > key): | |
A[i + 1] = A[i] | |
i = i - 1 | |
A[i + 1] = key | |
print(A) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment