public member function
<queue>

std::priority_queue::push

void push (const value_type& val);
void push (const value_type& val);void push (value_type&& val);
Insert element
Inserts a new element in the priority_queue. The content of this new element is initialized to val.

This member function effectively calls the member function push_back of the underlying container object, and then reorders it to its location in the heap by calling the push_heap algorithm on the range that includes all the elements of the container.

Parameters

val
Value to which the inserted element is initialized.
Member type value_type is the type of the elements in the container (defined as an alias of the first class template parameter, T).

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// priority_queue::push/pop
#include <iostream>       // std::cout
#include <queue>          // std::priority_queue

int main ()
{
  std::priority_queue<int> mypq;

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

  std::cout << "Popping out elements...";
  while (!mypq.empty())
  {
     std::cout << ' ' << mypq.top();
     mypq.pop();
  }
  std::cout << '\n';

  return 0;
}

Output:
Popping out elements... 100 40 30 25


Complexity

One call to push_back on the underlying container and one call to push_heap on the range that includes all the elements of the underlying container.

Data races

The container and up to all its contained elements are modified.

Exception safety

Provides the same level of guarantees as the operations performed on the underlying container object.

See also