module Queue where
type SlowQueue a = [a]
emptySlowQueue :: SlowQueue a
emptySlowQueue = []
isEmptySlowQueue :: SlowQueue a -> Bool
isEmptySlowQueue = null
enSlowQueue :: a -> SlowQueue a -> SlowQueue a
enSlowQueue x q = q ++ [x]
slowNext :: SlowQueue a -> a
slowNext = head
deSlowQueue :: SlowQueue a -> SlowQueue a
deSlowQueue = tail
data Queue a = Queue [a] [a]
emptyQueue :: Queue a
emptyQueue = Queue [] []
isEmptyQueue :: Queue a -> Bool
isEmptyQueue (Queue xs ys) = null xs && null ys
enqueue :: a -> Queue a -> Queue a
enqueue x (Queue xs ys) = queue xs (x:ys)
queue :: [a] -> [a] -> Queue a
queue [] ys = Queue (reverse ys) []
queue xs ys = Queue xs ys
next :: Queue a -> a
next (Queue (x:xs) _) = x
dequeue :: Queue a -> Queue a
dequeue (Queue (_:xs) ys) = queue xs ys
-- Invariant (solves all our problems):
-- If the first list is empty, the second one is empty, too.