Stacks & Queues
Master LIFO and FIFO data structures with visual push, pop, enqueue, and dequeue operations.
Category: Data Structures
·
v1.0.0
Step 1 of 6
Step 1: What are Stacks & Queues?
Stacks and Queues are two of the most fundamental data structures in computer science. They both store collections of elements, but differ in the order elements are added and removed.
Stack — LIFO (Last In, First Out): Think of a stack of plates. You add plates to the top and remove from the top. The last plate placed is the first one taken off.
Queue — FIFO (First In, First Out): Think of a line at a store. The first person in line is the first to be served. New people join at the back.
Key Terms:
- Push — Add an element to the top of a stack
- Pop — Remove the top element from a stack
- Enqueue — Add an element to the rear of a queue
- Dequeue — Remove the element from the front of a queue
- Peek — View the top (stack) or front (queue) element without removing it
- Top — The most recently added element in a stack
- Front / Rear — The first and last elements in a queue
Stack (LIFO)
Plate A
Plate B
Plate C ← Top
Push ↑ and Pop ↓ from the top
Queue (FIFO)
Front →
Person B
← Rear
Dequeue from front, Enqueue at rear
About This Lab
Stacks and Queues are fundamental data structures used everywhere from browser history to print queues. In this lab, you'll visualize how stacks follow LIFO (Last In, First Out) and queues follow FIFO (First In, First Out), implement core operations, solve real-world problems, and understand when to use each.
How It Works
- Read each step's explanation
- Push and pop items on the interactive stack
- Enqueue and dequeue items in the interactive queue
- Solve bracket matching and other exercises
- Complete the quiz to test your understanding