Sorting algorithms/Radix sort: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added boilerplate to the sort's preamble.)
Line 2,858: Line 2,858:
<lang rexx>/*REXX program performs a radix sort on an integer array (can be negative/zero/positive)*/
<lang rexx>/*REXX program performs a radix sort on an integer array (can be negative/zero/positive)*/
call gen /*call subroutine to generate numbers. */
call gen /*call subroutine to generate numbers. */
call radSort n /*invoke the radix sort subroutine. */
call radSort n, w /*invoke the radix sort subroutine. */
call show /*display the elements in the @ array*/
call show /*display the elements in the @ array*/
exit /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: ILF= 0 2 3 4 5 5 7. 6 6 7 11 7 13 9 8 8 17 8 19 9 10 13 23 9 10 15 ,
gen: ILF= 0 2 3 4 5 5 7. 6 6 7 11 7 13 9 8 8 17 8 19 9 10 13 23 9 10 15 ,
Line 2,872: Line 2,872:
end /*m*/; return /*W: is the maximum width ↑ of numbers*/
end /*m*/; return /*W: is the maximum width ↑ of numbers*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
radSort: procedure expose @. w; parse arg size; mote= c2d(' '); #= 1; !.#._n= size
radSort: procedure expose @.; parse arg size,w; mote= c2d(' '); #= 1; !.#._n= size
!.#._b= 1; if w=='' then w= 8
!.#._b= 1
!.#._i= 1; do i=1 for size; y=@.i; @.i= right(abs(y), w, 0); if y<0 then @.i= '-'@.i
!.#._i= 1; do i=1 for size; y=@.i; @.i= right(abs(y), w, 0); if y<0 then @.i= '-'@.i
end /*i*/ /* [↑] negative case.*/
end /*i*/ /* [↑] negative case.*/