Anonymous user
Sorting algorithms/Counting sort: Difference between revisions
→{{header|Haskell}}: removed need for scoped type variables
Underscore (talk | contribs) (Added Haskell.) |
(→{{header|Haskell}}: removed need for scoped type variables) |
||
Line 220:
We use lists for input and output rather than arrays, since lists are used more often in Haskell.
<lang haskell>
import Data.Array.ST
countingSort ::
countingSort l lo hi = concat $ zipWith replicate count [lo..]
where count = runST $ do
a <-
let increment i = readArray a i >>= writeArray a i . (+1)
mapM_ increment l
getElems a
myNewArray :: (Ix n) => (n,n) -> Int -> ST s (STArray s n Int)
myNewArray = newArray</lang>
=={{header|Java}}==
|