Skip to content

Stack queue

Stacks and Queues

These are linear data structures that control how data is added and removed.

1. Stack (LIFO)

  • Logic: "Last-In, First-Out".
  • Analogy: A stack of plates. You add a plate to the top, and you take the top plate off first.
  • Operations:
    • Push: Add item to top.
    • Pop: Remove item from top.

2. Queue (FIFO)

  • Logic: "First-In, First-Out".
  • Analogy: A line of people waiting for a bus. The person who arrived first is served first.
  • Operations:
    • Enqueue: Add item to the end.
    • Dequeue: Remove item from the front.

Applications

  • Stacks are used for "Undo" features and Function Calls (The Call Stack).
  • Queues are used for printer tasks and handling web requests.