isEmpty empty == True
isEmpty (fromList []) == True
isEmpty (fromList [ 1 ]) == FalseGet the first element added to the queue without modifying the queue.
peek empty == Nothing
peek (fromList [ 1, 2, 3 ]) == Just 1
peek (enqueue 3 (enqueue 2 (enqueue 1 empty))) == Just 1Add an element to the back of the queue.
toList (enqueue 1 empty) == [ 1 ]
toList (enqueue 2 (fromList [ 1 ])) == [ 1, 2 ]The worst-case time is O(1).
Remove and return the first element added to the queue.
dequeue empty == Nothing
dequeue (enqueue 1 empty) == Just ( 1, empty )
dequeue (enqueue 2 (fromList [ 1 ])) == Just ( 1, fromList [ 2 ] )The worst-case time is O(n). However, a sequence of n enqueue and dequeue operations
starting from an empty queue has a total running time of O(n). Therefore,
the amortized time per operation is O(1).
A linear data structure where elements are added to the back (enqueue) and removed from the front (dequeue).