Created
January 8, 2012 20:19
-
-
Save zallarak/1579541 to your computer and use it in GitHub Desktop.
Insertion Sort (Ruby)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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