Sorting algorithms/Cocktail sort: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 778: | Line 778: | ||
</lang> |
</lang> |
||
=={{header|Arturo}}== |
|||
<lang rebol>trySwap: function [arr,i][ |
|||
if arr\[i] < arr\[i-1] [ |
|||
tmp: arr\[i] |
|||
arr\[i]: arr\[i-1] |
|||
arr\[i-1]: tmp |
|||
return null |
|||
] |
|||
return true |
|||
] |
|||
cocktailSort: function [items][ |
|||
t: false |
|||
l: size items |
|||
while [not? t][ |
|||
t: true |
|||
loop 1..dec l 'i [ |
|||
if null? trySwap items i -> |
|||
t: false |
|||
] |
|||
if t -> break |
|||
loop (l-1)..1 'i [ |
|||
if null? trySwap items i -> |
|||
t: false |
|||
] |
|||
] |
|||
return items |
|||
] |
|||
print cocktailSort [3 1 2 8 5 7 9 4 6]</lang> |
|||
{{out}} |
|||
<pre>1 2 3 4 5 6 7 8 9</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
contributed by Laszlo on the ahk [http://www.autohotkey.com/forum/post-276379.html#276379 forum] |
contributed by Laszlo on the ahk [http://www.autohotkey.com/forum/post-276379.html#276379 forum] |