cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : priority_queue : pop
- -
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::pop public member function
void pop ( );

Remove top element

Removes the element on top of the priority_queue, effectively reducing its size by one. The value of this element can be retrieved before being popped by calling member priority_queue::top.

This calls the removed element's destructor.

This member function effectively calls the pop_heap algorithm to keep the heap property of priority_queues and then calls the member function pop_back of the underlying container object to remove the element.


Parameters

none

Return value

none

Example

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

int main ()
{
  priority_queue<int> mypq;

  mypq.push(30);
  mypq.push(100);
  mypq.push(25);
  mypq.push(40);

  cout << "Popping out elements...";
  while (!mypq.empty())
  {
     cout << " " << mypq.top();
     mypq.pop();
  }
  cout << endl;

  return 0;
}

Output:

Popping out elements... 100 40 30 25


Complexity

Constant (in the priority_queue). Although notice that pop_heap operates on logarithmic time.

See also

priority_queue::push Insert element (public member function)
priority_queue::empty Test whether container is empty (public member function)

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