Queues
Another leading subject of Chapter 5, Stacks and Queues, was a queue. This is also a representative of limited access data structures. While using a queue, you can only add new elements at the end (the enqueue operation) and remove the element from the queue only from the beginning of the queue (the dequeue operation). For this reason, this data structure is consistent with the FIFO principle, which stands for First-In First-Out. The built-in implementation as the Queue
class is available for you, as well.
The illustration of a queue is shown as follows:
Figure 10.5 – Illustration of a queue
It is also possible to use a priority queue, which extends the concept of a queue by setting the priority for each element. Thus, the dequeue operation returns the element with the highest priority, which was added earliest to the queue. When all elements with the highest priority are dequeued, the priority queue handles elements with the next highest...