Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
- mergeBy cmp [] ys = ys
- mergeBy cmp xs [] = xs
- mergeBy cmp (x : xs) (y : ys)
- | cmp x y == GT = y : mergeBy cmp (x : xs) ys
- | cmp x y == LT = x : mergeBy cmp xs (y : ys)
- | otherwise = x : y : mergeBy cmp xs ys
- instance PQueue Heap where
- toPQueue cmp xs = foldr insert (Heap cmp Nil) xs
- fromPQueue (Heap cmp Nil) = []
- fromPQueue (Heap cmp (Node i t1 a t2)) = a : mergeBy cmp (fromPQueue (Heap cmp t1)) (fromPQueue (Heap cmp t1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement