Similar questions 1 more →
Stacks & Queues


Answer & solution
Answer: A (no official key was published)
1. Keep p at the rear, whose next pointer is the front. Enqueue inserts after p and advances p to the new rear; dequeue removes p.next, with a special empty result for a singleton.
2. Both take constant time, A. Keeping only the front would require finding its predecessor to update the rear link.
3. Teaching check: For enqueue, set new.next=p.next, then p.next=new and p=new. For dequeue, remove p.next and advance that link; if it was the sole node, mark the queue empty. A circular rear pointer therefore exposes both ends without a predecessor scan.