Skip to content

Instantly share code, notes, and snippets.

@firstspring1845
Last active August 29, 2015 14:11
Show Gist options
  • Save firstspring1845/f0895979283ea485ec4e to your computer and use it in GitHub Desktop.
Save firstspring1845/f0895979283ea485ec4e to your computer and use it in GitHub Desktop.
わかる
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