Anonymous user
Sorting algorithms/Radix sort: Difference between revisions
m
→{{header|REXX}}: added a subroutine, optimized the sort algorithm, add/changed comments and whitespace.
m (→{{header|Groovy}}: elided style from PRE tag.) |
m (→{{header|REXX}}: added a subroutine, optimized the sort algorithm, add/changed comments and whitespace.) |
||
Line 2,386:
call gen /*call subroutine to generate numbers. */
call radSort n /*invoke the radix sort subroutine. */
call show
end /*j*/ /* [↑] display sorted items ───► term.*/▼
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 2,401 ⟶ 2,400:
/*──────────────────────────────────────────────────────────────────────────────────────*/
radSort: procedure expose @. w; parse arg size; mote= c2d(' '); #= 1; !.#._n= size
!.#._b= 1
!.#._i= 1; do i=1 for size; y=@.i;
end /*i*/
do while #\==0;
#= #-1
do j=low for n; parse var @.j =($) _ +1; ctr._= ctr._ + 1
if ctr._==1 & _\=='' then do; if _<<L then L=_; if _>>H then H=_
end /* ↑↑ */
Line 2,417 ⟶ 2,416:
L= c2d(L); H= c2d(H); ?= ctr._ + low; top._= ?; ts= mote
max= L
do k=L to H; _= d2c(k, 1); c= ctr._
if c>ts then parse value c k with ts max; ?= ?+c; top._= ?
end /*k*/
Line 2,426 ⟶ 2,425:
if piv>=c then leave; top._= c; ?= @.c; @.c= it; it= ?
end /*forever*/
top._= piv;
end /*while piv<low+n */
i= max
Line 2,442 ⟶ 2,441:
end /*while #\==0 */
#= 0 /* [↓↓↓] handle neg. and pos. arrays. */
do i=size by -1
end /*i*/
do j=1 for size; if @.j>=0 then do; #= #+1; @@.#= @.j; end; @.j= @@.j+0
end /*j*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do j=1 for n; say 'item' right(j, w) "after the radix sort:" right(@.j, w)
{{out|output|text= (with the middle section elided.)}}
|