From the course: C++ Standard Template Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Priority queues

Priority queues - C++ Tutorial

From the course: C++ Standard Template Library

Start my 1-month free trial

Priority queues

- [Instructor] Now we are ready to talk about the priority queue container adapter. Recall that a priority queue is a container that keeps its elements ordered naturally. This is because it's implemented as a heap, which is a data structure that has the behavior of a binary tree, which keeps its elements ordered; and the way to use a priority queue is by pushing elements in any order, but you will only be able to pop the maximum of those elements. And so everything you pop back will be in descending order. We will do this demo as an adaptation the same way we've been doing it before. Here we'll take the demo of the queue, and we will turn it into the priority queue behavior. First, I will change the initial comment to priority queue; and, interestingly enough, the header file where the prior queue is defined, is the same queue header file. So the first adaption will be in line number 10 where we change the queue by a priority queue. The next modification is a bit odd, and it will have…

Contents