{-# OPTIONS -Wall #-} -------------------------------------------------------------------------------- -- Only need to keep track of the minimum element. type PQ a = (Maybe a,Int) -- Creates a new priority queue. -- Time complexity: O(1). empty :: PQ a empty = (Nothing,0) -- Inserts an element. -- Time complexity: O(1). insert :: Ord a => a -> PQ a -> PQ a insert e1 (me,s) = (Just $ maybe e1 (min e1) me, s+1) -- Returns the minimum if there is one, else nothing. -- Time complexity: O(1). findMin :: PQ a -> Maybe a findMin = fst -- Returns the size. -- Time complexity: O(1). size :: PQ a -> Int size = snd --------------------------------------------------------------------------------