Class: Algorithmable::Sort::Merge
- Inherits:
-
Object
- Object
- Algorithmable::Sort::Merge
- Defined in:
- lib/algorithmable/sort/merge.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.sort(collection) ⇒ Object
4 5 6 |
# File 'lib/algorithmable/sort/merge.rb', line 4 def self.sort(collection) new.sort(collection) end |
Instance Method Details
#sort(collection) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/algorithmable/sort/merge.rb', line 8 def sort(collection) return collection if collection.size <= 1 mid = collection.size / 2 left = collection[0...mid] right = collection[mid...collection.size] merge(sort(left), sort(right)) end |