Last active
August 29, 2015 14:02
-
-
Save shosanna/005a8b35083fcb741b80 to your computer and use it in GitHub Desktop.
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
# Insertion sort | |
def insertion_sort(a) | |
1.upto(a.length - 1) do |i| | |
x = a[i] | |
j = i - 1 | |
while j >= 0 && a[j] > x | |
a[j + 1] = a[j] | |
j -= 1 | |
end | |
a[j + 1] = x | |
end | |
return a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment