The priority_queue class supports a single-ended priority queue. Its template specification is shown here:

template <class T, class Container = vector<T>,
               class Comp = less<Container::value_type> >
               class priority_queue

Here, T is the type of data being stored. Container is the type of container used to hold the queue, and Comp specifies the comparison function that determines when one member of the priority queue is lower in priority than another. It has the following constructors:

explicit priority_queue(const Comp &cmpfn = Comp( ),
                Container &cnt = Container( ));
template <class InIter> priority_queue(InIter start, InIter end,
                const Comp &cmpfn = Comp( ),
                Container &cnt = Container( ));

The first priority_queue( ) constructor creates an empty priority queue. The second creates a priority queue that contains the elements specified by the range start and end. By default, it uses a vector as a container. You can also use a deque as a container for a priority queue. The container is held in a protected object called c of type Container.

priority_queue contains the following member functions:



bool empty( ) const;

Returns true if the invoking priority queue is empty and false otherwise.

void pop( );

Removes the first element in the priority queue.

void push(const T &val);

Adds an element to the priority queue.

size_type size( ) const;

Returns the number of elements currently in the priority queue.

const value_type &top( ) const;

Returns a reference to the element with the highest priority. The element is not removed.

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539 © 2008-2017.
If you may any questions please contact us: