Contents:
A queue is a FIFO Data structure (First in-First out). It is also known as FCFS (First come-First served)
A real-life example of a queue is a queue in a bank - the person who is at the front of the queue will be served first, and the new people who come into the bank will stand at the end of the queue and they will be served last. this means that we add new elements at the end of the queue and we remove them from the front.
We use queues in programming whenever we need things to happen in the exact order they were called, but the computer cannot keep up with the speed and execute those things fast enough.
In this situation, we put those things in a queue and we process/remove them from the front and add new things at the end of the queue.
The most common example of how queues are used in programming is the way a printer works - you can send multiple pages to print, but because printer takes a few seconds to print each page, all pages will be in a queue waiting for their turn to be printed, and they will be printed in the exact order they were sent to print.
I’m also going to share some examples of how I use queues in my programming work, and I’ll explain the code of STL Queue and teach you about the most important functions used with queues:
#cplusplus #programming #developer