After performing this set of operations, what does the final list contain?…

2024

After performing this set of operations, what does the final list contain?

InsertFront(10);

InsertFront(20);

InsertRear(30);

DeleteFront();

InsertRear(40);

InsertRear(10);

DeleteRear();

InsertRear(15);

display();

  1. A.

    10 30 10 15

  2. B.

    20 30 40 15

  3. C.

    20 30 40 10

  4. D.

    10 30 40 15

Attempted by 13 students.

Show answer & explanation

Correct answer: D

A deque (double-ended queue) allows insertion and deletion at BOTH ends independently: InsertFront/DeleteFront act on the front, InsertRear/DeleteRear act on the rear, unlike a plain queue (only rear-in, front-out) or a stack (only one end). Because the same operation name can appear more than once in a sequence, each call must be executed in the exact order given, not skipped as a 'repeat'.

  1. InsertFront(10) places 10 into the empty deque: 10

  2. InsertFront(20) places 20 ahead of 10 at the front: 20, 10

  3. InsertRear(30) appends 30 at the rear: 20, 10, 30

  4. DeleteFront() removes 20 from the front: 10, 30

  5. InsertRear(40) appends 40 at the rear: 10, 30, 40

  6. InsertRear(10) appends another 10 at the rear: 10, 30, 40, 10

  7. DeleteRear() removes the just-added 10 from the rear: 10, 30, 40

  8. InsertRear(15) appends 15 at the rear: 10, 30, 40, 15

Independent check (reverse simulation): undoing the operations from the final state in reverse order returns the deque to empty, confirming the trace is consistent - undo InsertRear(15) to remove 15 from the rear, undo DeleteRear() by reinserting 10 at the rear, undo InsertRear(10) to remove that 10 from the rear, undo InsertRear(40) to remove 40 from the rear, undo DeleteFront() by reinserting 20 at the front, undo InsertRear(30) to remove 30 from the rear, undo InsertFront(20) to remove 20 from the front, and undo InsertFront(10) to remove the last 10 - leaving the deque empty, exactly as it started.

Explore the full course: Coding For Placement

Loading lesson…