Exercise 10.2.3
Implement a queue by using a singly linked list
L. The operationsENQUEUEandDEQUEUEshould still take $\O(1)$ time.
This is a bit trickier than the previous one, but still simple.
- We need to keep track of the last element of the list.
- Whenever we
ENQUEUE, we should be inserting the element after it and marking the new last element of the list. - Whenever we
DEQUEUE, we should pop the first element of the list.