From the course: Complete Guide to C++ Programming Foundations

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Queues and stacks

Queues and stacks

- [Speaker] Let's explore two useful container adapters from the STL. These are queues and stacks. Both adapters work by default over the underlying deck container, but they could work with a vector or a list if you want. A queue is a FIFO data structure, which is short for First In First Out. This means that the first element added is the first one to be removed. On the other hand, a stack is a LIFO data structure, which is short for Last In First Out. This means the last element added is the first to be removed. This example shows the usage of a queue and a stack in an adventure game where different player events can come from the player before they can be performed by the game engine. So a queue of events is useful to keep the order of the requested events for the game engine when it's ready to process them. In line six, I included the queue header and in line nine I declared a queue of strings named eventQueue. Then in lines 12 through 14, we are simulating three incoming event…

Contents