Last active
August 29, 2015 14:26
-
-
Save acapilleri/46a05f58ab5981e4c4ce 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 mergesort(ary) | |
return ary if ary.count <= 1 | |
size = ary.count | |
m = size / 2 | |
merge mergesort(ary[0..m-1]), mergesort(ary[m..size-1]) | |
end | |
def merge(a, b) | |
return a if b.count <= 0 | |
return b if a.count <= 0 | |
min = a.first > b.first ? b.shift : a.shift | |
[min] + merge(a,b) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment