function [ B ] = quicksort( A )
%QUICKSORT simple implementation of quicksort
%   Minas Spetsakis Nov. 2017

if length(A)<=1
    B=A;
    return
end
mid = A(1);

i=2;
j=length(A);
while i<=j
    while (i<=j)&(A(j)>=mid)
        j=j-1;
    end
    while (i<=j)&(A(i)<=mid)
        i=i+1;
    end
    if i<j
        t=A(i);
        A(i)=A(j);
        A(j)=t;
        j=j-1;
        i=i+1;
    end
end
t=A(1);
A(1)=A(j);
A(j)=t;
B=[quicksort(A(1:j-1)),mid,quicksort(A(i:length(A)))];

end

