Created
November 23, 2008 03:48
-
-
Save renaehodgkins/28023 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
# http://sheelkapur.com/2008/09/22/ruby-insertion-sort/ | |
def insertion_sort (list) | |
list.each_with_index do |element, index| | |
index.downto(0) do |j| | |
if (j > 0 && element < list[j-1]) then | |
list[j] = list[j-1] | |
else | |
list[j] = element | |
break | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment