Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
  2. mergeBy cmp [] ys = ys
  3. mergeBy cmp xs [] = xs
  4. mergeBy cmp (x : xs) (y : ys)
  5.   | cmp x y == GT = y : mergeBy cmp (x : xs) ys
  6.   | cmp x y == LT = x : mergeBy cmp xs (y : ys)
  7.   | otherwise = x : y : mergeBy cmp xs ys
  8.  
  9. instance PQueue Heap where
  10.   toPQueue cmp xs = foldr insert (Heap cmp Nil) xs
  11.   fromPQueue (Heap cmp Nil) = []
  12.   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