Sorting algorithms/Counting sort: Difference between revisions

(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 = concatconcatMap (uncurry $ zipWithflip replicate) count [lo..]
where count = runST $ do
a <- myNewArray (lo, hi) 0
let increment i = readArray a i >>= writeArray a i . (+1)
mapM_ increment l
getElemsgetAssocs a
myNewArray :: (Ix n) => (n,n) -> Int -> ST s (STArray s n Int)
myNewArray = newArray</lang>
Anonymous user