Skip to main contentSkip to solution

Arrange the following operations in the correct order to delete an element from the front of a deque implemented using a doubly linked list:

A. Set front = front->next

B. Check if deque is empty

C. Free the memory of the old front node

D. If deque becomes empty, set rear = NULL

Solution

✅ Correct Option: 4

B. Check if deque is empty. If it is, there is nothing to delete (underflow), so this must come first.

A. Set front = front->next. The old front node is still held by a temporary pointer, and front now points to the second node.

C. Free the memory of the old front node, once front has moved past it.

D. If deque becomes empty, set rear = NULL. This is checked last, after front has moved: if front is now NULL, rear must also be set to NULL. Otherwise rear would point to freed memory.


Option 1: freeing the old front before moving front loses the link to front->next.

Option 2: deleting without first checking for an empty deque causes underflow.

Option 3: the empty-deque fix-up (D) comes only after the old node has been freed (C), so it is the last step.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question