Sorting algorithms/Counting sort: Difference between revisions

m
→‎{{header|REXX}}: corrected a misspelling. -- ~~~~
m (Improved D entry)
m (→‎{{header|REXX}}: corrected a misspelling. -- ~~~~)
Line 1,242:
 
=={{header|REXX}}==
<lang rexx>/*REXX program sorts an array using the count-sort method. */
<lang rexx>
/*REXX program sorts an array using the count-sort method. */
 
call gen@ /*generate array elements. */
call show@ 'before sort' /*show before array elements*/
Line 1,250 ⟶ 1,248:
call show@ ' after sort' /*show after array elements*/
exit
 
 
/*─────────────────────────────────────countSORT subroutine────────*/
countSort: procedure expose @.; parse arg n
h=@.1
L=h
do m=2 to n
 
do L=min(L,@.m=2 to n)
L h=minmax(Lh,@.m)
h=max(h,@.m) end
end
 
_.=0
do j=1 for n
 
do j=1 for n k=@.j
_.k=@_.jk+1
_.k=_.k+1 end
end
 
#=1
do j=L to h
 
do if _.j\=L=0 tothen hdo #=# for _.j
if _.j\==0 then do #=# for _ @.#=j
@.#=j end
end
end
 
return
 
 
 
 
/*─────────────────────────────────────GEN@ subroutine─────────────*/
gen@: @.='' /*assign default value. */
 
/* get the first 40 Recaman numbers: subtract if you can, */
/* otherwise add. Another way: Recaman(1) = 1, */
/* Recaman(n) = Recaman(n-1)-n if positive and new, else */
/* Recaman(n) = Recaman(n-1)+n */
 
@.1 = 1
@.2 = 3
Line 1,336 ⟶ 1,321:
highItem=highItem-1 /*adjust highItem slightly. */
return
 
 
/*─────────────────────────────────────SHOW@ subroutine────────────*/
show@: widthH=length(highItem) /*maximum width of any line.*/
Line 1,345 ⟶ 1,328:
end
 
say copies('─',80) /*show a seperatorseparator line. */
return</lang>
'''output'''
</lang>
Output:
<pre style="height:30ex;overflow:scroll">
element 1 before sort: 1