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 priority queue

The following table shows commonly used priority queue APIs:

API

Description

push()

This appends a new value at the back of the priority queue

pop()

This removes the value at the front of the priority queue

empty()

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

size()

This returns the number of values stored in the priority queue

top()

This returns the value in the front of the priority queue

 

Let's write a simple program to understand priority_queue:

#include <iostream>#include <queue>#include <iterator>#include <algorithm>using namespace std;int main () {  priority_queue<int> q;  q.push( 100 );  q.push( 50 );  q.push( 1000 ); q.push( ...

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