Understanding the Queue Data Structure
Queues are a type of data structure that manages data in a first in first out format. This means that the first thing that enters the queue is the first thing that is removed from the queue. They are used in a variety of applications, such as simulation, and process management. Queues follow the same general structure as stacks, in the sense that they use a single Node object to keep track of all the data contained within them. For that matter, we can use the exact same Node we wrote for our stack object in the implementation of the queue. The key difference lies in how we insert the values into the structure.
Consider a situation where we want to make a queue of integers. If we were to insert the values 2, 3, and 4 in the order given, we would get a queue like below.
If we wanted to insert a new value, say the number 5, we would need to add it to the end of the queue.
If we want to remove a value from the queue, we would remove the first value in the queue, since the first value is the first value removed.