Similar to a stack, a queue is also a simple linear data structure that abstracts all of the elements from the user except the first and last ones. The only difference between a stack and a queue is that a stack allows you to operate only on the last element, whereas a queue allows you to operate both on the first and last elements.
It can be implemented using any linear data structures, such as an array, vector, or LinkedList.
Graphically, we can represent it as follows:
From the previous diagram, we can understand the following:
- Front: 0th index of the queue (backed up linear data structure)
- Rear: Last index of the queue (backed up linear data structure)