Main difference between Stack and Queue is how elements are added and removed.
Stack
- Order: Last In, First Out (LIFO)
- Operations:
- Push: Add an element to the top
- Pop: Remove the top element
- Use Case: Undo functionality in software, where the last action is undone first.
- Example:
- Stack (Top → Bottom):
- [5]
- [3]
- [1] ← First inserted
- Pop removes 5, the last inserted.
Queue
- Order: First In, First Out (FIFO)
- Operations:
- Enqueue: Add an element to the end
- Dequeue: Remove the front element
- Use Case: Print queue, where the first document sent is printed first.
- Example:
- Queue (Front → Rear):
- [1] ← First inserted
- [3]
- [5]
- Dequeue removes 1, the first inserted.




