Sorting algorithms/Cocktail sort: Difference between revisions
Content deleted Content added
Added Forth version |
|||
Line 540: | Line 540: | ||
</pre> |
</pre> |
||
=={{header|Forth}}== |
|||
<lang forth>defer precedes ( addr addr -- flag ) |
|||
\ e.g. ' < is precedes |
|||
: sort ( a n --) |
|||
1- cells bounds 2>r false |
|||
begin |
|||
0= dup |
|||
while |
|||
2r@ ?do |
|||
i @ i cell+ @ over over precedes ( mark unsorted ) |
|||
if drop drop else i ! i cell+ ! dup xor then |
|||
1 cells +loop |
|||
0= dup |
|||
while |
|||
2r@ swap 1 cells - ?do |
|||
i @ i cell+ @ over over precedes ( mark unsorted ) |
|||
if drop drop else i ! i cell+ ! dup xor then |
|||
-1 cells +loop |
|||
repeat then drop 2r> 2drop |
|||
;</lang> |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
{{works with|Fortran|90 and later}} |
{{works with|Fortran|90 and later}} |