Sorting algorithms/Cocktail sort: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
(added RPL) |
||
Line 3,834: | Line 3,834: | ||
end |
end |
||
</syntaxhighlight> |
</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}}== |
=={{header|Ruby}}== |