Sorting algorithms/Counting sort: Difference between revisions

Content added Content deleted
(→‎{{header|NetRexx}}: Add a more Rexx-like version)
Line 1,022: Line 1,022:


===Version 2===
===Version 2===
A more Rexx-like (and shorter) version. Due to NetRexx's built in indexed string capability negative values are also easily supported.
A more Rexx-like (and shorter) version. Due to NetRexx's built in indexed string capability, negative values are also easily supported.
<lang NetRexx>/* NetRexx */
<lang NetRexx>/* NetRexx */
options replace format comments java crossref symbols nobinary
options replace format comments java crossref symbols nobinary
Line 1,045: Line 1,045:
end
end
end ix
end ix
return ocounts
return ocounts.space


-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getMinMax(icounts) public constant binary returns Rexx
method getMinMax(icounts) public constant binary returns Rexx


amin = Integer.MAX_VALUE
amin = Long.MAX_VALUE
amax = Integer.MIN_VALUE
amax = Long.MIN_VALUE
loop x_ = 1 to icounts.words
loop x_ = 1 to icounts.words
if icounts.word(x_) < amin then
amin = icounts.word(x_).min(amin)
amin = icounts.word(x_)
amax = icounts.word(x_).max(amax)
if icounts.word(x_) > amax then
amax = icounts.word(x_)
end x_
end x_


Line 1,072: Line 1,070:


say icounts.space
say icounts.space
say countingSort(icounts).space
say countingSort(icounts)


return
return