Skip to content

Instantly share code, notes, and snippets.

@zallarak
Created January 8, 2012 20:19
Show Gist options
  • Save zallarak/1579541 to your computer and use it in GitHub Desktop.
Save zallarak/1579541 to your computer and use it in GitHub Desktop.
Insertion Sort (Ruby)
def InsertionSort(a)
a.each_with_index do |item, index|
i = index - 1
while i>=0
break if item >= a[i]
a[i+1] = a[i]
i -= 1
end
a[i+1] = item
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment