function out=mergesort(A)
if length(A)==1
    out = A;
else
    s = length(A);
    mid = floor(s/2);
    out1 = mergesort(A(1:mid));
    out2 = mergesort(A(mid+1:end));
    out = merge(out1, out2);
end