Skip to content

Instantly share code, notes, and snippets.

@kevbuchanan
Created October 16, 2013 17:10
Show Gist options
  • Select an option

  • Save kevbuchanan/7011344 to your computer and use it in GitHub Desktop.

Select an option

Save kevbuchanan/7011344 to your computer and use it in GitHub Desktop.
Insertion Sort - Ruby
def insertion_sort(array)
0.upto(array.length - 1).each do |index|
element = array[index]
position = index
while element < array[position - 1] && position > 0
array[position] = array[position - 1]
array[position - 1] = element
position -= 1
end
end
array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment