Skip to content

Language

Sign in

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

The stack data structure

Remember

  • A stack is LIFO; push and pop happen at the top.
  • Python: append() to push, pop() to pop, [-1] to peek; check for underflow.
  • Postfix: push operands; on an operator pop two, apply, push the result.

Quick self-check

  1. How can a stack reverse a string?

    Check

    Push each character, then pop them all; they come out in reverse order.

  2. What does stack[-1] do?

    Check

    It reads the top item without removing it.

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?