Data structures help us organize and manage data efficiently. Stack and Queue are two simple and commonly used data structures that store data in a particular order. Let’s first understand what a Stack is.
What is a Stack?
A stack is like a pile of things placed one on top of another. Imagine a stack of plates in your kitchen. You always put a new plate on the top, and when you need one, you take the top plate off. You can’t take a plate from the middle or the bottom without removing the ones above it.
This is exactly how a stack works in programming. It follows the rule called LIFO, which means Last In, First Out. Simply put, the last thing you add is the first thing you take out.

Real-Life Examples of Stack:
- A pile of books or plates.
- Apps or games use the undo button to reverse your last action first.
- Going back in your browser history (the last page you opened comes up first when you click back).
Do you want to learn about Linked List
How a Stack Works:
- You push an item to the top.
- You pop the item from the top.
- You peek at the top item without removing it, or check the top.
Simple Example:
Let’s say you push numbers 10, 20, and 30 into a stack. The stack now looks like this:
Top -> 30
20
Bottom->10
If you pop, 30 will be removed first because it was the last number you added.
What is a Queue?
A queue is just like a line of people waiting for something — like at a bus stop or a movie theater. The person who comes first gets served first. A queue works the same way in programming. It follows FIFO, which stands for First In, First Out.
This means the first thing you put into the queue is the first thing that comes out.
Real-Life Examples of Queue:
- People standing in line at a shop or a counter.
- Tasks waiting to be printed from your computer (the first document sent to the printer gets printed first).
- Customer calls waiting in a call center.
How a Queue Works:
- You add an item to the back of the line — this is called Enqueue.
- You remove the item from the front of the line — this is called Dequeue.
- You check the item at the front without removing it — this is called Front or Peek.
Simple Example:
If you enqueue numbers 10, 20, and 30 into a queue, it looks like this:
Front -> 10, 20, 30 <- Rear
If you dequeue, 10 will come out first because it was the first number you added.
Difference Between Stack and Queue
Stack | Queue |
Like a stack of plates (LIFO) | Like a line at a shop (FIFO) |
Last item in, first item out | First item in, first item out |
Add and remove from the top only | Add from the rear, remove from the front |
Used in undo buttons, browser history | Used in lines, waiting tasks, call queues |
Where Are They Used in Real Life?
Apps use stacks for undo features. Browsers use them to go back to previous pages. Programmers use stacks to handle function calls when one function calls another.
Customer service handles call lines using queues. Printers use queues to manage tasks. Computers process jobs one by one with queues, and websites use them to handle multiple user requests efficiently.
Simple Way to Remember:
Stack = Last thing goes in, first thing comes out.
(Like a stack of plates.)
Queue = First thing goes in, first thing comes out.
(Like standing in line.)
Conclusion:
Stacks and Queues are simple but powerful concepts used everywhere in technology. Once you understand them, it becomes easier to solve many real-life problems in programming. You’ll see these concepts used in apps, websites, games, and even in how your phone or computer works behind the scenes.
FAQ:
Stack and Queue in data structure pdf
Stack in data structure
What are the types of stacks?
What is stack and queue?
The advantages of stack?
Types of queue in data structure