Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

priority_queue


Container Adaptor

Summary

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

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <queue>
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 the default comparison operator (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 gives front(), push_back(), and pop_back(). In particular, deque and vector can be used.

Interface

template <class T, class Container = vector<T>,
          class Compare = less<typename
                          Container::value_type> >
 class priority_queue {
public:

// typedefs
   typedef typename Container::value_type value_type;
   typedef typename Container::size_type size_type;
   typedef Container container_type;

//  Construct
   explicit priority_queue (const Compare& = Compare(),
                            const Container& = Container());
   template <class InputIterator>
     priority_queue (InputIterator first,
                     InputIterator last,
                     const Compare& = Compare(), 
                     const Container& = Container());
   bool empty () const;
   size_type size () const;
   const value_type& top () const;
   void push (const value_type&);
   void pop();
};

Constructors

explicit priority_queue (const Compare& x = Compare(),
                         const Container& = Container());
template <class InputIterator>
priority_queue (InputIterator first, InputIterator last,
                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

Program Output

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 would not be able to write:

Instead, you would have to write:

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

Containers, queue



Previous fileTop of documentContentsIndexNext file
Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998