Skip to main contentSkip to solution

IF STACK 'S' is implemented with the list, having elements [23,24,35,37], The TOP of the STACK element is 37. After that, the following operations take place in sequence.

  1. PUSH(40)
  2. PUSH(43)

3.POP( )

  1. PUSH(56)

What will be the order of elements in the STACK 'S' after the completion of the above operations?

Solution

✅ Correct Option: 1

A stack follows LIFO (last in, first out): PUSH adds at the top (end of the list) and POP removes the top element.

OperationStack (bottom to top)
Start23, 24, 35, 37
PUSH(40)23, 24, 35, 37, 40
PUSH(43)23, 24, 35, 37, 40, 43
POP() removes 4323, 24, 35, 37, 40
PUSH(56)23, 24, 35, 37, 40, 56

Option 2: ignores the POP and the final PUSH(56).

Option 3: wrongly removes 40, but POP removes the most recent push, which is 43.

Keyboard Shortcuts

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