Queues/Stacks
Queues are a type of container with a first-in-first-out behavior. Conversely, a stack is a container with a last-in-first-out behavior. When adding elements to a queue, they are added to the end of the queue, and elements will be popped or peeked from the front. When adding elements to a stack, we can think of them as being added to the top, and then elements will also be popped or peeked from the top. This is the difference between first-in-first-out and last-in-first-out. Both of these containers are very useful when elements need to be retrieved and removed in a particular order; the end-of-chapter activity will utilize a queue to handle going through elements in a defined order.
Constructors
When constructing a queue, we can also decide what the underlying container for that queue will be. The same applies to a stack. If we do not choose a container type for ourselves then, by default, std::deque
will be used.
The template declaration of a queue and...