Skip to content

Instantly share code, notes, and snippets.

@omedale
Created April 3, 2019 11:10
Show Gist options
  • Select an option

  • Save omedale/d661d0ccb4b962b33a22eac9725afe52 to your computer and use it in GitHub Desktop.

Select an option

Save omedale/d661d0ccb4b962b33a22eac9725afe52 to your computer and use it in GitHub Desktop.
Ruby Implementation of Insertion Sort
def insertion_sort(array)
return array if array.size <= 1
(array.size).times do |j|
while j > 0
if array[j - 1] > array[j]
array[j - 1], array[j] = array[j], array[j - 1]
else
break
end
j -= 1
end
end
array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment