Sorting algorithms/Strand sort: Difference between revisions

(→‎{{header|Ruby}}: used partition)
Line 1,504:
 
x = (strand_sort nat-nleq) <3,1,5,4,2></lang>output:<pre><1,2,3,4,5></pre>
 
=={{header|zkl}}==
<lang zkl>fcn strandSort(A){ //--> new list, A is cleared, should add A=A.copy()
sublist:=List.createLong(A.len()); results:=List.createLong(A.len());
while(A){
sublist.clear(A.pop(0));
foreach i in (A.len() - 1){
if(A[i]>sublist[-1]) sublist.append(A.pop(i));
}
results.merge(sublist);
}
results
}</lang>
The createLong list method creates a new list with pre-allocated space
<lang zkl>strandSort(L(3,1,5,4,2)).println();
strandSort("azbfe".split("")).println();</lang>
{{out}}
<pre>
L(1,2,3,4,5)
L("a","b","e","f","z")
</pre>
 
{{omit from|GUISS}}
Anonymous user