Sorting algorithms/Cocktail sort: Difference between revisions
Content added Content deleted
(Updated to work with current version of Nim (1.4).) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 32: | Line 32: | ||
:* [https://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort_with_shifting_bounds cocktail sort with shifting bounds] |
:* [https://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort_with_shifting_bounds cocktail sort with shifting bounds] |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F cocktailSort(&A) |
|||
L |
|||
L(indices) ((0 .< A.len-1).step(1), (A.len-2 .. 0).step(-1)) |
|||
V swapped = 0B |
|||
L(i) indices |
|||
I A[i] > A[i + 1] |
|||
swap(&A[i], &A[i + 1]) |
|||
swapped = 1B |
|||
I !swapped |
|||
R |
|||
V test1 = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0] |
|||
cocktailSort(&test1) |
|||
print(test1)</lang> |
|||
{{out}} |
|||
<pre> |
|||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|||
</pre> |
|||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
Line 111: | Line 134: | ||
-31 0 1 2 2 4 45 58 65 69 74 82 82 83 88 89 99 104 112 782 |
-31 0 1 2 2 4 45 58 65 69 74 82 82 83 88 89 99 104 112 782 |
||
</pre> |
</pre> |
||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |