Sorting algorithms/Cocktail sort: Difference between revisions

(Added an ActionScript version.)
Line 758:
#end sub
}</lang>
 
=={{heading|PL/I}}==
<lang PL/I>
cocktail: procedure (A);
declare A(*) fixed;
declare stable bit (1);
declare (i, n) fixed binary (31);
 
n = hbound(A,1);
do until (stable);
stable = '1'b;
do i = 1 to n-1, n-1 to 1 by -1;
if A(i) > A(i+1) then
do; stable = '0'b; /* still unsorted, so set false. */
t = A(i); A(i) = A(i+1); A(i+1) = t;
end;
end;
end;
end cocktail;
</lang>
 
=={{header|PureBasic}}==
The following approach improves on the method in the pseudo-code by not examining indexes on either end of the array that have already been sorted by reducing the index range on each subsequent pass.
Anonymous user