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

  • 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

Step by Step Solution

3.50 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Sure heres the completed implementation of the doublelist queue in Haskell Ive also included comment... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!