Sorting algorithms/Counting sort: Difference between revisions
Content deleted Content added
→{{header|Julia}}: A new entry for Julia |
m →version 1: changed indentations, whitespace, separator, and comments, also simplified the "counting" DO loop. |
||
Line 1,744:
=={{header|REXX}}==
===version 1===
<lang rexx>/*REXX program sorts an array using the
#=words($); do j=1 for #
call show@ 'before sort' /*show the before array elements.*/▼
call countSort # /*sort # entries of the @. array.*/
call show@ ' after sort: ' /*show the after array elements.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────COUNTSORT subroutine────────────────*/
countSort:
▲_.=0; do j=1 for N; x=@.j; _.x=_.x+1; end /*j*/
▲ end /*x*/
end /*k*/▼
return
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
show@:
▲say copies('─',50) /*show a pretty separator line. */
return</lang>
'''output'''
<pre style="height:50ex">
element 1 before sort: 1
element 2 before sort: 3
element 3 before sort: 6
element 4 before sort: 2
element 5 before sort: 7
element 6 before sort: 13
element 7 before sort: 20
element 8 before sort: 12
element 9 before sort: 21
element 10 before sort: 11
element 11 before sort: 22
element 12 before sort: 10
element 13 before sort: 23
element 14 before sort: 9
element 15 before sort: 24
element 16 before sort: 8
element 17 before sort: 25
element 18 before sort: 43
element 19 before sort: 62
element 20 before sort: 42
element 21 before sort: 63
element 22 before sort: 41
element 23 before sort: 18
element 24 before sort: 42
element 25 before sort: 17
element 26 before sort: 43
element 27 before sort: 16
element 28 before sort: 44
element 29 before sort: 15
element 30 before sort: 45
element 31 before sort: 14
element 32 before sort: 46
element 33 before sort: 79
element 34 before sort: 113
element 35 before sort: 78
element 36 before sort: 114
element 37 before sort: 77
element 38 before sort: 39
element 39 before sort: 78
element 40 before sort: 38
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
element 1 after sort: 1
element 2 after sort: 2
element 3 after sort: 3
element 4 after sort: 6
element 5 after sort: 7
element 6 after sort: 8
element 7 after sort: 9
element 8 after sort: 10
element 9 after sort: 11
element 10 after sort: 12
element 11 after sort: 13
element 12 after sort: 14
element 13 after sort: 15
element 14 after sort: 16
element 15 after sort: 17
element 16 after sort: 18
element 17 after sort: 20
element 18 after sort: 21
element 19 after sort: 22
element 20 after sort: 23
element 21 after sort: 24
element 22 after sort: 25
element 23 after sort: 38
element 24 after sort: 39
element 25 after sort: 41
element 26 after sort: 42
element 27 after sort: 42
element 28 after sort: 43
element 29 after sort: 43
element 30 after sort: 44
element 31 after sort: 45
element 32 after sort: 46
element 33 after sort: 62
element 34 after sort: 63
element 35 after sort: 77
element 36 after sort: 78
element 37 after sort: 78
element 38 after sort: 79
element 39 after sort: 113
element 40 after sort: 114
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
</pre>
|