Sorting algorithms/Insertion sort: Difference between revisions

Added a solution for MATLAB
(→‎{{header|Eiffel}}: Added "works with" template showing need for provisional syntax support.)
(Added a solution for MATLAB)
Line 576:
 
print(unpack(isort{4,5,2,7,8,3}))</lang>
 
=={{header|MATLAB}}==
This is a direct translation of the pseudo-code above, except that it has been modified to compensate for MATLAB's 1 based arrays.
<lang MATLAB>function list = insertionSort(list)
 
for i = (2:numel(list))
value = list(i);
j = i - 1;
while (j >= 1) && (list(j) > value)
list(j+1) = list(j);
j = j-1;
end
list(j+1) = value;
end %for
end %insertionSort</lang>
 
Sample Usage:
<lang MATLAB>>> insertionSort([4 3 1 5 6 2])
 
ans =
 
1 2 3 4 5 6</lang>
 
 
=={{header|Modula-3}}==
Anonymous user