Write and test the double-list implementation of Queues in Queue2.hs. Again, you can include an automatically derived
Question:
- Write and test the double-list implementation of Queues in Queue2.hs. Again, you can include an automatically derived Show instance for Queue a that I put in a comment so that you can see the data representation, but make sure you remove it or comment it out again when you are confident that it works
This is in Haskell please
module Queue2 (Queue, mtq, ismt, addq, remq) where
---- Interface ----------------
mtq :: Queue a -- empty queue
ismt :: Queue a -> Bool -- is the queue empty?
addq :: a -> Queue a -> Queue a -- add element to front of queue
remq :: Queue a -> (a, Queue a) -- remove element from back of queue;
-- produces error "Can't remove an element
-- from an empty queue" on empty
--- Implementation -----------
{- In this implementation, a queue is represented as a pair of lists.
The "front" of the queue is at the head of the first list, and the
"back" of the queue is at the HEAD of the second list. When the
second list is empty and we want to remove an element, we REVERSE the
elements in the first list and move them to the back, leaving the
first list empty. We can now process the removal request in the usual way.
-}
data Queue a = Queue2 [a] [a] -- deriving Show
mtq = undefined
ismt = undefined
addq x q = undefined
remq q = undefined
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood