Skip to content

Language

Sign in

Learn › Class 12 › Computer Science / Informatics Practices › File handling and data structures (stack)

The stack data structure

Example 1: Trace a sequence of operations

Open one step at a time. Try the next step yourself first.

  1. Step 1. Start with an empty stack [].
  2. Show step 2

    push 5, push 8: [5, 8].

  3. Show step 3

    pop removes 8: [5].

  4. Show step 4

    push 3, push 7: [5, 3, 7].

  5. Show step 5

    pop removes 7: the stack is [5, 3].

Example 2: Evaluate the postfix expression 6 2 3 + *

Open one step at a time. Try the next step yourself first.

  1. Step 1. Push 6, 2, 3: [6, 2, 3].
  2. Show step 2

    + pops 3 and 2, pushes 5: [6, 5].

  3. Show step 3

    * pops 5 and 6, pushes 30: [30].

  4. Show step 4

    The answer is 30.

Reviewed by EduFlint team on 1 Dec 2026 · version 1

Written by us for this site. Independent; not affiliated with NCERT or CBSE.

Report a mistake

Looking for another topic?