Game Development Reference
In-Depth Information
Listing 17-5. The queue Container
using namespace std;
using MyQueue = queue<int>;
MyQueue myQueue;
myQueue.emplace(0);
myQueue.emplace(1);
myQueue.emplace(2);
cout << "Front of the queue: " << myQueue.front() << endl;
myQueue.pop();
The call to front in Listing 17-5 would print 0 to the console. After the call to pop , a call to front
would result in 1 being returned. The queue class also provides a back method to retrieve the last
element in a queue , but you cannot remove this element. I haven't shown this method in action,
as I have never found much use for it. The queue container is used for its first in, first out properties.
Summary
This chapter was short and sweet. The stack and queue containers are much more limited than other
containers. Although their purpose is to store elements in a manner similar to the other containers
provided by the STL, they are actually designed to provide restrictions on how you can access their
elements.
The stack provides a last in, first out access pattern, whereas the queue provides a first in, first out
pattern.
The next chapter covers the last type of STL container you will see in this topic, the bitset .
 
Search WWH ::




Custom Search