Sorting algorithms/Strand sort: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: removed deprecated given/when syntax) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 10: | Line 10: | ||
This is a way of sorting numbers by extracting shorter sequences of already sorted numbers from an unsorted list. |
This is a way of sorting numbers by extracting shorter sequences of already sorted numbers from an unsorted list. |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F merge_list(&a, &b) |
|||
[Int] out |
|||
L !a.empty & !b.empty |
|||
I a[0] < b[0] |
|||
out.append(a.pop(0)) |
|||
E |
|||
out.append(b.pop(0)) |
|||
out [+]= a |
|||
out [+]= b |
|||
R out |
|||
F strand(&a) |
|||
V i = 0 |
|||
V s = [a.pop(0)] |
|||
L i < a.len |
|||
I a[i] > s.last |
|||
s.append(a.pop(i)) |
|||
E |
|||
i++ |
|||
R s |
|||
F strand_sort(&a) |
|||
V out = strand(&a) |
|||
L !a.empty |
|||
out = merge_list(&out, &strand(&a)) |
|||
R out |
|||
print(strand_sort(&[1, 6, 3, 2, 1, 7, 5, 3]))</lang> |
|||
{{out}} |
|||
<pre> |
|||
[1, 1, 2, 3, 3, 5, 6, 7] |
|||
</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |