Last active
August 29, 2015 14:11
-
-
Save firstspring1845/f0895979283ea485ec4e 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 merge(arr) | |
org = self.reverse | |
arr = arr.reverse | |
new = [] | |
loop{ | |
if org == [] | |
return new.concat(arr.reverse) | |
end | |
if arr == [] | |
return new.concat(org.reverse) | |
end | |
if org.last < arr.last | |
new << org.pop | |
else | |
new << arr.pop | |
end | |
} | |
new | |
end | |
def merge_sort | |
a = self.map{|e|[e]} | |
while a.size != 1 do | |
a = a.each_slice(2).map{|a|a.size == 1 ? a[0] : a[0].merge(a[1])} | |
end | |
a[0] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment