Skip to content

Instantly share code, notes, and snippets.

@NathanEpstein
Last active February 22, 2016 21:37
Show Gist options
  • Save NathanEpstein/1109d3f4b542bc9eb8a2 to your computer and use it in GitHub Desktop.
Save NathanEpstein/1109d3f4b542bc9eb8a2 to your computer and use it in GitHub Desktop.
insertion sort in ruby
def insertion_sort(array)
for i in 1..array.length-1
j = i
while j > 0 && array[j-1] > array[j]
pivot = array[j]
array[j] = array[j-1]
array[j-1] = pivot
j -= 1
end
end
array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment