2014-10-24 23:44:13 +00:00
|
|
|
module QueueEx where
|
|
|
|
|
|
|
|
import Control.Applicative
|
|
|
|
import Data.Dequeue (BankersDequeue)
|
|
|
|
import qualified Data.Dequeue as Q
|
|
|
|
import Data.Maybe
|
|
|
|
|
|
|
|
|
|
|
|
-- |Shift a queue to the left, such as:
|
|
|
|
-- [1, 2, 3] -> [2, 3, 1]
|
|
|
|
shiftQueueLeft :: BankersDequeue a -> BankersDequeue a
|
2015-09-04 22:51:12 +00:00
|
|
|
shiftQueueLeft = (\(Just (b, nq)) -> Q.pushBack nq b) <$> Q.popFront
|
2014-10-24 23:44:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- |Shift a queue to the right, such as:
|
|
|
|
-- [1, 2, 3] -> [3, 1, 2]
|
|
|
|
shiftQueueRight :: BankersDequeue a -> BankersDequeue a
|
2015-09-04 22:51:12 +00:00
|
|
|
shiftQueueRight = (\(Just (b, nq)) -> Q.pushFront nq b) <$> Q.popBack
|
2014-10-24 23:44:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- |Convert a Queue back to a list.
|
|
|
|
queueToList :: BankersDequeue a -> [a]
|
|
|
|
queueToList q = Q.takeFront (Q.length q) q
|