Created
June 7, 2009 11:04
-
-
Save daqing/125287 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 insertion_sort(seq) | |
(1..seq.size - 1).each do |i| | |
key = seq[i] | |
left = i - 1 | |
while left >= 0 and seq[left] > key | |
seq[left + 1] = seq[left] | |
seq[left] = key | |
left -= 1 | |
end | |
end | |
seq | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment