Created
July 31, 2015 22:18
-
-
Save 284km/f4adb270c524056448f0 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
class Array | |
def insertion_sort | |
return self if size < 2 | |
1.upto(size - 1) do |i| | |
# tmp = self[i] | |
i.downto(1) do |j| | |
if self[j - 1] > self[j] | |
self[j - 1], self[j] = self[j], self[j - 1] | |
p self | |
else | |
break | |
end | |
end | |
end | |
self | |
end | |
end | |
a = (1..10).to_a.shuffle | |
p a | |
p a.insertion_sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment