Namespaces
Variants

std::priority_queue<T,Container,Compare>:: push

From cppreference.net

void push ( const value_type & value ) ;
(1)
void push ( value_type && value ) ;
(2) (C++11 이후)

주어진 요소 value 를 우선순위 큐에 푸시합니다.

1) 다음과 동일함: c. push_back ( value ) ; std:: push_heap ( c. begin ( ) , c. end ( ) , comp ) ; .
2) 동등한 표현: c. push_back ( std :: move ( value ) ) ; std:: push_heap ( c. begin ( ) , c. end ( ) , comp ) ; .

목차

매개변수

value - 푸시할 요소의 값

반환값

(없음)

복잡도

비교 연산의 로그 횟수에 Container :: push_back 의 복잡도를 더한 값.

예제

#include <iostream>
#include <queue>
struct Event
{
    int priority{};
    char data{' '};
    friend bool operator<(Event const& lhs, Event const& rhs)
    {
        return lhs.priority < rhs.priority;
    }
    friend std::ostream& operator<<(std::ostream& os, Event const& e)
    {
        return os << '{' << e.priority << ", '" << e.data << "'}";
    }
};
int main()
{
    std::priority_queue<Event> events;
    std::cout << "Fill the events queue:\t";
    for (auto const e : {Event{6,'L'}, {8,'I'}, {9,'S'}, {1,'T'}, {5,'E'}, {3,'N'}})
    {
        std::cout << e << ' ';
        events.push(e);
    }
    std::cout << "\nProcess events:\t\t";
    for (; !events.empty(); events.pop())
    {
        Event const& e = events.top();
        std::cout << e << ' ';
    }
    std::cout << '\n';
}

출력:

Fill the events queue:  {6, 'L'} {8, 'I'} {9, 'S'} {1, 'T'} {5, 'E'} {3, 'N'}
Process events:         {9, 'S'} {8, 'I'} {6, 'L'} {5, 'E'} {3, 'N'} {1, 'T'}

참고 항목

(C++11)
제자리에서 요소를 생성하고 기반 컨테이너를 정렬합니다
(public member function)
최상위 요소를 제거합니다
(public member function)