Skip to content

Instantly share code, notes, and snippets.

@renaehodgkins
Created November 23, 2008 03:48
Show Gist options
  • Save renaehodgkins/28023 to your computer and use it in GitHub Desktop.
Save renaehodgkins/28023 to your computer and use it in GitHub Desktop.
# 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