Sorting Algorithms/Circle Sort: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: simplified main subroutine. |
m →{{header|REXX}}: made subroutines to simplify making of array, list. |
||
Line 303:
<lang rexx>/*REXX program uses a circle sort to sort an array (or list) of numbers.*/
parse arg x; if x='' then x=6 7 8 9 2 5 3 4 1 /*use the defaults ? */
do i=1 for #; @.i=word(x,i); end /*assign numbers to the array @.*/▼
call circleSort # /*invoke circle sort subroutine. */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────CIRCLESORT subroutine───────────────*/
Line 329 ⟶ 322:
swaps=.circleSrt(low+mid+1, high, swaps) /* " higher, */
return swaps /*section done. */
/*──────────────────────────────────one─liner subroutines───────────────*/
.swap: arg a,b; parse value @.a @.b with @.b @.a; swaps=swaps+1; return
▲make@:
'''output''' when using the default inputs:▼
makeY: y=@.1; do j=2 to #; y=y @.j; end; say arg(1) y; return</lang>
<pre>
before sort: 6 7 8 9 2 5 3 4 1
|