Code covered by the BSD License  

Highlights from
Merge sorted arrays

Merge sorted arrays

by

 

03 Oct 2010 (Updated )

Given two already sorted arrays, the function combines them in an unique sorted array

mergesort(a)
function a = mergesort(a)

n = numel(a);
if n>=2
   split = floor((1+n)/2);
   a1 = mergesort(a(1:split));
   a2 = mergesort(a(split+1:end));
   a = mergemex(a1,a2);
end

Contact us