Skip to content

Instantly share code, notes, and snippets.

@felipernb
Created September 14, 2012 08:52
Show Gist options
  • Select an option

  • Save felipernb/3720853 to your computer and use it in GitHub Desktop.

Select an option

Save felipernb/3720853 to your computer and use it in GitHub Desktop.
Insertion Sort in Ruby
def insertion_sort(a)
for i in 1..a.length-1 do
n = a[i]
pos = i
while pos > 0 and a[pos-1] > n do
a[pos] = a[pos-1]
pos -= 1
end
a[pos] = n
end
a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment