Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Q elt = Construct [elt] [elt]
- enqueue :: (Q a) -> a -> (Q a)
- enqueue (Construct f b) el = Construct f (b : el)
- dequeue :: (Q a) -> Maybe (a, Q a)
- dequeue (Construct f b) =
- if length f > 0 then ((head f), Construct (tail f) b) else if length b == 0 then Nothing else ((head b_rev), Construct (tail b_rev) [])
- where
- b_rev = reverse b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement