-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueue.hs
More file actions
32 lines (25 loc) · 757 Bytes
/
Queue.hs
File metadata and controls
32 lines (25 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Queue where
-- Queue using two lists - front & rear
data Queue a =
Queue [a] [a]
deriving (Eq, Show)
-- create an empty Queue
empty :: Queue a
empty = error "todo"
-- check if given queue is empty
isEmpty :: Queue a -> Bool
isEmpty = error "todo"
-- Return next element to be removed from Queue
head :: Queue a -> Maybe a
head = error "todo"
-- Return Queue without head (element to be removed)
tail :: Queue a -> Maybe (Queue a)
tail = error "todo"
-- Add elements to rear
snoc :: a -> Queue a -> Queue a
snoc = error "todo"
-- Ensure the invariant
-- `front` can be empty if and only if `rear` is empty
-- When `front` becomes empty, reverse rear make it the front and make rear empty
check :: [a] -> [a] -> Queue a
check = error "todo"