Member-only story
Software Engineer Study Guide — Stack vs. Queue
Oct 27, 2020
Stack
- LIFO (Last in First out)
- Same end is used to insert and delete elements
- 1 pointer used
- Operations: Push and Pop
- Check empty condition: Top == -1
- Check full condition: Top == Max-1
- No variants
- Implementation is simpler than queue
Queue
- FIFO (First in First out)
- One end is used for insertion and the other end is used for deletion of elements
- 2 pointers used (in simple queue case)
- Operations: Enqueue and dequeue
- Check empty condition: Front == -1 || Front == Rear+1
- Check full condition: Rear == Max-1
- It has variants like circular queue, priority queue and doubly ended queue
- Implementation is comparatively more complex than stack