If the elements 1, 2, 3, and 4 are pushed, in this order, onto an initially…

2025

If the elements 1, 2, 3, and 4 are pushed, in this order, onto an initially empty stack, with no removals between pushes, what is the order in which all elements are popped?

Answer: C. 4321ConceptA stack follows the Last In, First Out (LIFO) rule: insertion and removal both occur at the top. Therefore, when several elements are pushed without…

  1. A.

    1234

  2. B.

    2134

  3. C.

    4321

  4. D.

    None of the above

Attempted by 918 students.

Show answer & explanation

Correct answer: C

Concept

A stack follows the Last In, First Out (LIFO) rule: insertion and removal both occur at the top.

Therefore, when several elements are pushed without any intervening pop, the pop order is the reverse of the push order.

Application

  1. Begin with an empty stack.

  2. Push 1, then 2, then 3, then 4. From bottom to top, the stack is [1, 2, 3, 4], so 4 is at the top.

  3. Pop repeatedly: 4 leaves first, followed by 3, then 2, and finally 1.

Cross-check

Reversing the push order 1, 2, 3, 4 gives 4, 3, 2, 1, exactly as LIFO requires.

Thus, the removal order is 4321.

Explore the full course: Coding For Placement

Loading lesson…