module Algorithmable::Cups
Public Instance Methods
merge_arrays(left, right)
click to toggle source
right = [4, 2, 1] left = [7, 6, 5, 3]
l1 = [1] l2 = []
# File lib/algorithmable/cups/merge_two_arrays.rb, line 15 def merge_arrays(left, right) sorted = [] while !left.empty? && !right.empty? if left[0] >= right[0] sorted.push(left.shift) else sorted.push(right.shift) end end sorted += left if right.empty? sorted += right if left.empty? sorted # [1] end