cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : priority_queue : top
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
priority_queue
priority_queue::priorit...
member functions:
· priority_queue::empty
· priority_queue::pop
· priority_queue::push
· priority_queue::size
· priority_queue::top

-

priority_queue::top public member function
const value_type& top ( ) const;

Access top element

Returns a constant reference to the top element in the priority_queue. The top element is the element that compares higher in the priority_queue, and the next that is removed from the container when priority_queue::pop is called.

This member function effectively calls the member function front of the underlying container object.

Parameters

none

Return value

A reference to the top element in the priority_queue.

Member type value_type is defined to the type of value contained by the underlying container, which shall be the same as the first template parameter (T).

Example

// priority_queue::top
#include <iostream>
#include <queue>
using namespace std;

int main ()
{
  priority_queue<int> mypq;

  mypq.push(10);
  mypq.push(20);
  mypq.push(15);

  cout << "mypq.top() is now " << mypq.top() << endl;

  return 0;
}

Output:

mypq.top() is now 20

Complexity

Constant.

See also

priority_queue::pop Remove top element (public member function)
priority_queue::push Insert element (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us