A Queue is a FIFO (First In First Out — the element placed at first can be accessed at first) structure which can be commonly found in many programming languages. This structure is named as “queue” because it resembles a real-world queue — people waiting in a queue (line).
Just like in like real life, the person who was in line first gets served first.
Given below are the 2 basic operations that can be performed on a queue. Reference the diagram above
- Enqueue: Insert an element to the end of the queue.
- Dequeue: Delete the element from the beginning of the queue.
Applications of Queues
- Used to manage threads in multithreading.
- Used to implement queuing systems (e.g.: priority queues).