Skip to content

Instantly share code, notes, and snippets.

@jnf
jnf / mergesort.rb
Last active August 29, 2015 14:25 — forked from sudocrystal/mergesort.rb
Starting ground for mergesort in ruby -- with recursive and iterative solutions.
def mergesort(a)
# if the array size is 0|1 then the list is considered sorted, return sorted
return a if a.length <= 1
# split the list in half
left, right = split_array a
# merge sort each half
sorted_left = mergesort left
sorted_right = mergesort right