Skip to content

Instantly share code, notes, and snippets.

@acapilleri
Last active August 29, 2015 14:26
Show Gist options
  • Save acapilleri/46a05f58ab5981e4c4ce to your computer and use it in GitHub Desktop.
Save acapilleri/46a05f58ab5981e4c4ce to your computer and use it in GitHub Desktop.
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