Jump to content

Sorting algorithms/Cocktail sort: Difference between revisions

added RPL
m (→‎{{header|Wren}}: Changed to Wren S/H)
(added RPL)
Line 3,834:
end
</syntaxhighlight>
 
=={{header|RPL}}==
{{works with|RPL|HP-49C}}
« '''DO''' 1 CF
1 OVER SIZE 1 - '''FOR''' h
DUP h DUP 1 + SUB
'''IF''' DUP EVAL > '''THEN'''
h SWAP REVLIST REPL
1 SF
'''ELSE''' DROP '''END'''
'''NEXT'''
'''IF''' 1 FS? '''THEN'''
DUP SIZE 1 - 1 '''FOR''' h
DUP h DUP 1 + SUB
'''IF''' DUP EVAL > '''THEN'''
h SWAP REVLIST REPL
1 SF
'''ELSE''' DROP '''END'''
-1 '''STEP'''
'''END'''
'''UNTIL''' 1 FC? '''END'''
» '<span style="color:blue">COCKTAILSORT</span>' STO
 
{ 7 6 5 9 8 4 3 1 2 0 } <span style="color:blue">COCKTAILSORT</span>
{{out}}
<pre>
1: { 0 1 2 3 4 5 6 7 8 9 }
</pre>
This implementation is 40 times slower than the built-in <code>SORT</code> function on an HP-50g.
 
=={{header|Ruby}}==
1,150

edits

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