Skip to content

Instantly share code, notes, and snippets.

@stormbrew
Created May 20, 2014 18:47
Show Gist options
  • Save stormbrew/4266c3b5267870f9af29 to your computer and use it in GitHub Desktop.
Save stormbrew/4266c3b5267870f9af29 to your computer and use it in GitHub Desktop.
def destructive_merge(a,b)
res = []
while !a.empty? && !b.empty?
while !a.empty? && a.first < b.first
res << a.shift
end
a, b = b, a
end
res
end
a = 100.times.collect { rand * 100 }.sort
b = 100.times.collect { rand * 100 }.sort
c = destructive_merge(a,b)
require 'pp'
pp c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment