Anonymous user
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. */▼
▲/*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
_.=0
do j=1 for n
_.k=
#=1
do j=L to h
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
return</lang>
'''output'''
<pre style="height:30ex;overflow:scroll">
element 1 before sort: 1
|