Sorting algorithms/Strand sort: Difference between revisions

Line 358:
[1, 2, 3, 3, 4, 5]
[1, 2, 3, 3, 3, 4, 5, 6]</pre>
 
=={{header|Mathematica}}==
<lang Mathematica>StrandSort[ input_ ] := Module[ {results = {}, A = input},
While[Length@A > 0,
sublist = {A[[1]]}; A = A[[2;;All]];
For[i = 1, i < Length@A, i++,
If[ A[[i]] > Last@sublist, AppendTo[sublist, A[[i]]]; A = Delete[A, i];]
];
results = #[[Ordering@#]]&@Join[sublist, results];];
results ]</lang>
Example usage :
<pre>StrandSort[{2, 3, 7, 5, 1, 4, 7}]
{1, 2, 3, 4, 5, 7, 7}</pre>
 
=={{header|NetRexx}}==