Skip to content

Instantly share code, notes, and snippets.

@shinokada
Created May 4, 2014 08:30
Show Gist options
  • Save shinokada/11512814 to your computer and use it in GitHub Desktop.
Save shinokada/11512814 to your computer and use it in GitHub Desktop.
def insertionsort(num)
for j in 1..(num.length - 1) do
key = num[j]
i = j - 1
while i >= 0 and num[i] > key
num[i+1] = num[i]
i = i - 1
end
num[i+1] = key
end
puts num
end
numbers = [23,34,46,87,12,1,66]
insertionsort(numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment