What is the difference between a stack and a queue?

A comparison of stack and queue data structures, their differences in functionality and use cases.

1 Answer

 A linear data structure that stores items in a Last In, First Out (LIFO) order, This means the last item added to the stack is the first one removed is called stack. Example: Imagine a stack of books you put books on top, and you remove the top book first.

A linear data structure that stores items in a First In, First Out (FIFO) order, This means the first item added to the queue is the first one removed is called queue. Example: Think of people standing in a line the first person in line gets served first.

We use cookies to enhance your experience, to provide social media features and to analyse our traffic. By continuing to browse, you agree to our Privacy Policy.