Jump to content

Sorting algorithms/Cocktail sort with shifting bounds: Difference between revisions

Added Arturo implementation
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(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}}==
1,532

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.