Anonymous user
Sorting algorithms/Cocktail sort: Difference between revisions
m
→{{header|REXX}}: optimized the (two) procedures.
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
m (→{{header|REXX}}: optimized the (two) procedures.) |
||
Line 2,742:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
cocktailSort: procedure expose @.; parse arg N; nn=
do until done; done= 1
do j=1
if @.j>@.jp then do; done=0; _=@.j; @.j=@.jp; @.jp=_; end
end /*j*/
if done then leave /*No swaps done? Finished*/
do k=
if @.k>@.kp then do; done=0; _=@.k; @.k=@.kp; @.kp=_; end
end /*k*/
Line 2,834:
This faster REXX version can handle an array that doesn't contain blanks or spaces by using a simpler ''swap'' mechanism.
<lang rexx>/*──────────────────────────────────────────────────────────────────────────────────────*/
cocktailSort2: procedure expose @.;
do until done; done= 1 /*array items
do j=1 for
if @.j>@.jp then parse value 0 @.j @.jp with done @.jp @.j
end /*j*/
if done then leave /*
do k=
if @.k>@.kp then parse value 0 @.k @.kp with done @.kp @.k
end /*k*/
|