Sorting algorithms/Cocktail sort with shifting bounds: Difference between revisions
Sorting algorithms/Cocktail sort with shifting bounds (view source)
Revision as of 09:34, 2 June 2021
, 3 years agoAdded Arturo implementation
m (→{{header|Phix}}: added syntax colouring the hard way) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 643:
</lang>
=={{header|Arturo}}==
<lang rebol>cocktailShiftSort: function [items][
a: new items
beginIdx: 0
endIdx: (size a)-2
while [beginIdx =< endIdx][
newBeginIdx: endIdx
newEndIdx: beginIdx
loop beginIdx..endIdx 'i [
if a\[i] > a\[i+1] [
tmp: a\[i]
a\[i]: a\[i+1]
a\[i+1]: tmp
newEndIdx: i
]
]
endIdx: newEndIdx - 1
loop endIdx..beginIdx 'i [
if a\[i] > a\[i+1] [
tmp: a\[i]
a\[i]: a\[i+1]
a\[i+1]: tmp
newBeginIdx: i
]
]
beginIdx: newBeginIdx - 1
]
return a
]
print cocktailShiftSort [3 1 2 8 5 7 9 4 6]</lang>
{{out}}
<pre>1 2 3 4 5 6 7 8 9</pre>
=={{header|AutoHotkey}}==
|