Created
August 30, 2010 00:15
-
-
Save danmelnick/556845 to your computer and use it in GitHub Desktop.
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
def insertion_sort(array) | |
n = 1 | |
while n < array.length | |
key = array[n] | |
i = n - 1 | |
while i >= 0 and array[i] > key | |
array[i + 1] = array[i] | |
i = i - 1 | |
end | |
array[i + 1] = key | |
n = n + 1 | |
end | |
return array | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment