Last Updated: May 22, 2026
std::priority_queue<T> is a container adapter that serves elements by priority instead of insertion order. By default, the element that compares largest comes out first, so it's a max-heap with a familiar push/top/pop interface. The adapter wraps a sequence container (a std::vector<T> by default) and exposes only the operations a heap needs. This chapter covers what a heap is, the small API the adapter offers, how to flip it into a min-heap, how to use custom comparators for objects, the typical workloads (task scheduling, top-K problems, Dijkstra), and the costs to be aware of.