Sorting Algorithms/Circle Sort: Difference between revisions

m
→‎{{header|REXX}}: elided useless testing statement.
(→‎{{header|REXX}}: simplified the REXX program by using a SWAP subroutine.)
m (→‎{{header|REXX}}: elided useless testing statement.)
Line 308:
do i=1 for #; @.i=word(x,i); end /*assign numbers to the array @.*/
/*array indices are easier to use*/
call circleSort 1, # /*invoke circle sort subroutine. */
y=@.1 /*start with the first element. */
do j=2 to #; y=y @.j; end /*assign array numbers to a list.*/
Line 315:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────CIRCLESORT subroutine───────────────*/
circleSort: procedure expose @.; parse arg lo,hi /*get the arguments HI index.*/
do while .circleSrt(1, hi, 0) \== 0; end /*invoke until done.*/
end /*while*/ /*···short but sweet*/
return /*circleSort is done*/
/*──────────────────────────────────.CIRCLESRT subroutine───────────────*/
.circleSrt: procedure expose @.; parse arg lo,hi,swaps /*get the args. */
if swaps=='' then swaps=0 /*assume zero ? */
if lo==hi then return swaps /*are we done ? */
high=hi; low=lo; mid=(hi-lo) % 2 /*assign indices*/
Line 329 ⟶ 327:
lo=lo+1; hi=hi-1 /*add; subtract.*/
end /*while lo<hi*/ /*just 1 section*/
hiphiP=hi+1 /*point to HI+1 .*/
if lo==hi then if @.lo>@.hiphiP then call .swap lo,hip hiP /*out of order? */
swaps=.circleSrt(low,low+mid,swaps) low+mid, swaps) /*sort lower. */
swaps=.circleSrt(low+mid+1, high,swaps) swaps) /* " higher, */
return swaps /*section done. */
/*──────────────────────────────────.SWAP subroutine────────────────────*/