STL

In the lesson, we'll see how to use C++ STL queue.

We'll cover the following

Library

While solving a problem, we’ll be using the queue from C++ STL.

Include statement: #include <queue>

Below are some of the operations we’ll be using frequently. For complete documentation of how they work, check here.

queue<int> Q; //empty queue
int x = Q.front(); // get front element
int x = Q.back(); //get back element
Q.pop(); // pop front element
Q.push(x); //push x at back
bool x = Q.empty(); // to check if stack is empty
int sz = Q.size(); // get size of stack

In the next chapter, we’ll move onto tree data structures starting with Binary Trees.

Get hands-on with 1200+ tech skills courses.