O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Commonly used APIs in a queue

The following table shows the commonly used queue APIs:

API

Description

push()

This appends a new value at the back of the queue

pop()

This removes the value at the front of the queue

front()

This returns the value in the front of the queue

back()

This returns the value at the back of the queue

empty()

This returns true when the queue is empty; otherwise it returns false

size()

This returns the number of values stored in the queue

 

Let's use a queue in the following program:

#include <iostream>#include <queue>#include <iterator>#include <algorithm>using namespace std;int main () {  queue<int> q;  q.push ( 100 );  q.push ( 200 );  q.push ( 300 ); cout << "\nValues in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required