ProgrammingVery hard

A queue with head and tail pointers is emptied by dequeuing its only node. What must the dequeue do to keep the queue correct?

  1. A. Set the tail pointer to NULL as well as the head
  2. B. Leave the tail pointing at the freed node
  3. C. Set the head to the tail's value only
  4. D. Free the tail and keep the head unchanged

Correct answer: A. Set the tail pointer to NULL as well as the head

If tail still points at the freed node, the next enqueue writes into freed memory. Both pointers must become NULL when the queue is empty.

More C Programming questions

Exams that ask this topic