DEV Community

marknathon449
marknathon449

Posted on

Difference between Stack and Queue Data Structure

Stack Data Structure

A Stack is a FILO (First In, Last Out) data structure in which the element that is added first is the last to be erased. At the top of the stack, operations like insertion (PUSH) and deletion of entries (POP) are done. Stacks are linear data structures because the items in them are ordered in a sequential order.

The following are some examples of stacks in practice
Arrangement of plates.
Arrangement of books in a cupboard.
Wearing or removing bangles from hands.

Stack operations of several kinds

The following are the most basic stack operations in the data structure:

push() - Adds a new element to the stack's top. It's an overflow if the stack is completely full.
pop() - Removes one element from the stack's top. It's an underflow if the stack is empty.
peek() - Displays the stack's topmost element.

Queue Data Structure

A Queue is a FIFO (First In, First Out) data structure in which the element that is added first is also the first to be deleted. Enqueue (insertion) and dequeue (removal) are the two most basic queue operations (deletion). The front of the queue is used to enqueue, and the back of the queue is used to dequeue. Because the pieces in a queue are ordered in a logical order, queues are referred to as linear data structures.

The following are some examples of queues in action

The customer who enters a store first will be served first.
Task scheduling on the CPU and disk scheduler.
In the case of bus and train tickets, there is a waiting list.

There are many difference between stack and queue and both have separate real world applications.

Top comments (0)