Created
March 18, 2012 12:47
-
-
Save farnoy/2071631 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(list) | |
| return list if list.size <= 1 | |
| mid = list.size / 2 | |
| merge mergesort(list[0, mid]), mergesort(list[mid, list.size]) | |
| end | |
| def merge(left, right) | |
| sorted = [] | |
| until left.empty? or right.empty? | |
| if left.first <= right.first | |
| sorted.push left.shift | |
| else | |
| sorted.push right.shift | |
| end | |
| end | |
| sorted.concat(left).concat(right) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment