Skip to content

Instantly share code, notes, and snippets.

@sudocrystal
Created July 23, 2015 16:52
Show Gist options
  • Save sudocrystal/8578ad90cf9bf1189de1 to your computer and use it in GitHub Desktop.
Save sudocrystal/8578ad90cf9bf1189de1 to your computer and use it in GitHub Desktop.
Starting ground for mergesort in ruby
def mergesort(a)
# if the array size is 0|1 then the list is considered sorted, return sorted
# split the list in half
# merge sort each half
# combine the sorted halves
end
def split_array(a)
# find the middle
# take = Returns first n elements from the array.
# drop = Drops first n elements and returns the rest of the elements.
# return left and right halves of array as separate arrays
end
def combine(a, b)
end
# TEST IT
a = [6,23,53,1,2,5,62,61,33,21,14,6,23]
a = a.shuffle
puts "ORIGINAL \n" + a.to_s
a = mergesort(a)
puts "AFTER MERGESORT \n" + a.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment