Difference Between Stack and Queue

Stack and queue are very similar to each other. The main difference between stack and queue is that stack uses Last In First Out principle and queue uses First In First Out principle.

First, we will study about stack and queue and then make a table comparing both.

Stack

Stack is a linear data structure. It is based on Last In First Out (LIFO) principle. It access/deletes most recent value first.

For example, in a buffet or party, plates are on top of each other. If we want to eat, we take the top plate on the top, not from the middle. This is a stack.

Basic Operations:

1. Push: inserts a value on top of the stack.
2. Pop: deletes value on top of the stack.
3. Top: prints value on top of the stack.

Queue

Queue is a linear data structure. It is based on First In First Out (LIFO) principle. It access/deletes the oldest value first.

For example, in a mall, the cashier serves the customer in front of the line first. This is a queue.

Basic Operations:

1. Enqueue: insert data at the end of the queue.
2. Dequeue: deletes data in front of the queue.
3. front: returns the data in front of the queue.

References

https://en.wikiversity.org/wiki/Data_Structures_and_Algorithms/Stacks_and_Queues