Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

priority_queue

Library:  Containers


Does not inherit

Local Index

Members

Summary

A container adapter that behaves like a priority queue. Items popped from the queue are in order with respect to a priority.

Synopsis

#include <queue>

namespace std {
  template <class T,
            class Container = vector<T>,
            class Compare = less<Container::value_type> >
  class priority_queue;
}

Description

priority_queue is a container adaptor that allows a container to act as a priority queue. This means that the item with the highest priority, as determined by either operator<() or the comparison Compare, is brought to the front of the queue whenever anything is pushed onto or popped off the queue.

priority_queue adapts any container that supports front(), push_back(), pop_back(), and has a random access iterator. In particular, deque and vector can be used. To instantiate a priority_queue, a comparison function object must be supplied.

Interface

Constructors

explicit priority_queue(const Compare& x = Compare(),
                          const Container& = Container());
template <class InputIterator>
priority_queue(InputIterator start, InputIterator finish,
                 const Compare& x = Compare(),
                 const allocator_type& alloc =
                 allocator_type());

Member Functions

bool 
empty() const;
void 
pop();
void 
push(const value_type& x);
size_type 
size() const;
const value_type& 
top() const;

Example

Warnings

If your compiler does not support default template parameters, you must always include a Container template parameter and a Compare template parameter when declaring an instance of priority_queue. For example, you must write:

instead of:

See Also

Containers, queue

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 23.2.3.2



Previous fileTop of DocumentContentsIndex pageNext file