Anonymous user
Sorting algorithms/Counting sort: Difference between revisions
→{{header|Haskell}}
(added ocaml version for arrays; maybe someone else can add one for lists) |
|||
Line 224:
countingSort :: (Enum n, Ix n) => [n] -> n -> n -> [n]
countingSort l lo hi =
where count = runST $ do
a <- myNewArray (lo, hi) 0
let increment i = readArray a i >>= writeArray a i . (+1)
mapM_ increment l
myNewArray :: (Ix n) => (n,n) -> Int -> ST s (STArray s n Int)
myNewArray = newArray</lang>
|