In this post, we will understand the difference between Stack and Queue.
They are based on LIFO- Last In First Out.
This means the element inserted at the end is the first element to get deleted.
Insertion and deletion happen in a stack from one end only, i.e the top.
Insert operation is known as ‘push’ operation.
Delete operation is known as ‘pop’ operation.
A pointer is used to access the list, it is known as ‘top’.
The ‘top’ points to the last element of the list.
It helps work with problems associated with recursion.
They are based on FIFO- First In First Out.
This means the element that is inserted first is the first element to be deleted from the queue.
Insertion and deletion happen from two opposite ends of the list.
Insertion happens from the rear end.
Deletion happens from the front end.
Insert operation is also known as ‘enqueue’.
Delete operation is also known as ‘dequeue’.
Two pointers are used to access the list.
Front pointer points to first element that is inserted in the list, and still present.
The rear pointer points to the last inserted element of the queue.
It is used to solve problems that have sequential processing techniques.