recieving error "Out of memory. The likely cause is an infinite recursion within the program." in MatLab : <p>I am trying to implement  quick sort in MatLab. I have two functions, one which splits a given list into two smaller lists, one greater and one smaller than the pivot. The second function recursively calls the quick sort and iterates to the next smaller list, calling quick sort again. My code is below. When I go to run the code with my list of 300 randomly generated numbers, I get the error "Out of memory. The likely cause is an infinite recursion within the program.".</p>

<pre><code>function [ less, pivot, greater ] = SplitList( list, pivotindex )
%List Splitting Function
%In order to preform quick sort you firts must be able to split the list 
%into two, one which is greater than, and one which is less than the pivot.

pivot = list(1,pivotindex);

greater = [];
less = [];

for l = 1:length(list)
    if list(1,l) &gt; pivot
        greater = [greater list(1, l)];
    else if list(1,l) &lt;= pivot
        less = [less list(1, l)];
        end
    end

end

end

function [ qs_list ] = quick_sort( list )
%Recursive Quick Sort
%   quick sort algorithm to sort a list of numbers

%set (0,'RecursionLimit',1000);
pivotindex = round(length(list)/2); %sets pivot at the median value of the array

if length(list) &gt; 1
    [ less, pivot, greater ] = SplitList( list, pivotindex ); %calls the SplitList function
    qs_list = [quick_sort(less) pivot quick_sort(greater)]; %calls quick_sort within the function

else
    qs_list = list;

end
end
</code></pre>
