priority_queue 클래스
A template container adaptor class that provides a restriction of functionality limiting access to the top element of some underlying container type, which is always the largest or of the highest priority. New elements can be added to the priority_queue and the top element of the priority_queue can be inspected or removed.
template <
class Type,
class Container=vector<Type>,
class Compare=less<typename Container::value_type>
>
class priority_queue
매개 변수
형식
The element data type to be stored in the priority_queue.Container
The type of the underlying container used to implement the priority_queue.비교
The type that provides a function object that can compare two element values as sort keys to determine their relative order in the priority_queue. This argument is optional and the binary predicate less*<typename Container*::value_type***>* is the default value.
설명
The elements of class Type stipulated in the first template parameter of a queue object are synonymous with value_type and must match the type of element in the underlying container class Container stipulated by the second template parameter. The Type must be assignable, so that it is possible to copy objects of that type and to assign values to variables of that type.
The priority_queue orders the sequence it controls by calling a stored function object of class Traits. 일반적으로, 요소는 이 순서를 설정하기 위해 비교 가능한 값보다 작을 필요가 있습니다: 제공된 어떤 두 요소에서도, 두 요소가 동일하거나(어떤 것도 다른 것보다 작지 않음) 하나가 다른 것보다 작음을 정할 수 있습니다. 그러면 동일하지 않은 요소 사이에 정렬이 수행됩니다. 더 기술적인 설명으로, 비교 함수는 표준 수학 의미로 엄밀한 약한 순서를 포함하는 이진 술어입니다.
Suitable underlying container classes for priority_queue include deque Class and the default vector Class or any other sequence container that supports the operations of front, push_back, and pop_back and a random-access iterator. The underlying container class is encapsulated within the container adaptor, which exposes only the limited set of the sequence container member functions as a public interface.
Adding elements to and removing elements from a priority_queue both have logarithmic complexity. Accessing elements in a priority_queue has constant complexity.
There are three types of container adaptors defined by the STL: stack, queue, and priority_queue. Each restricts the functionality of some underlying container class to provide a precisely controlled interface to a standard data structure.
The stack class supports a last-in, first-out (LIFO) data structure. A good analogue to keep in mind would be a stack of plates. Elements (plates) may be inserted, inspected, or removed only from the top of the stack, which is the last element at the end of the base container. The restriction to accessing only the top element is the reason for using the stack class.
The queue class supports a first-in, first-out (FIFO) data structure. A good analogue to keep in mind would be people lining up for a bank teller. Elements (people) may be added to the back of the line and are removed from the front of the line. Both the front and the back of a line may be inspected. The restriction to accessing only the front and back elements in this way is the reason for using the queue class.
The priority_queue class orders its elements so that the largest element is always at the top position. It supports insertion of an element and the inspection and removal of the top element. A good analogue to keep in mind would be people lining up where they are arranged by age, height, or some other criterion.
생성자
Constructs a priority_queue that is empty or that is a copy of a range of a base container object or of other priority_queue. |
형식 정의
A type that provides the base container to be adapted by a priority_queue. |
|
부호 없는 정수 형식은 priority_queue의 요소 갯수를 표현할 수 있습니다. |
|
A type that represents the type of object stored as an element in a priority_queue. |
멤버 함수
Tests if the priority_queue is empty. |
|
Removes the largest element of the priority_queue from the top position. |
|
Adds an element to the priority queue based on the priority of the element from operator<. |
|
다음 priority_queue내에 있는 요소 수를 반환합니다. |
|
Returns a const reference to the largest element at the top of the priority_queue. |
요구 사항
Header: <queue>
네임스페이스: std