std::priority_queue
Definido no cabeçalho <queue>
|
||
template< class T, |
||
Fila de prioridade é um adaptador de contêiner que permite obter seu valor máximo (padrão) em um tempo constante, ao custo de inserção e extração logarítmicas.
Um Compare
pode ser fornecido para mudar a ordem. Por exemplo, usar std::greater<T> faria o menor elemento ser retornado pelo método top().
Trabalhar com uma fila de prioridade
é semelhante a gerenciar uma pilha em um contêiner com acesso aleatório, com a vantagem de não ser possível invalidar a pilha por acidente.
Índice |
[editar] Parâmetros do template
T | - | O tipo dos elementos armazenados. O comportamento é indefinido se T não for o mesmo de Container::value_type . (desde C++17)
|
Container | - | O tipo de contêiner subjacente para armazenar os elementos. O contêiner deve satisfazer os requisitos de SequenceContainer, e seus iteradores devem satisfazer os requisitos de LegacyRandomAccessIterator. Além disso, ele deve fornecer as seguintes funções com semântica usual:
Os contêineres padrão std::vector e std::deque satisfazem estes requisitos. |
Compare | - | Uma comparação fornecendo ordenamento estritamente fraco.
Note que o parâmetro Compare é definido de forma a retornar true quando seu primeiro argumento "vem antes" do seu segundo argumento seguindo um ordenamento fraco. Porém, como a fila de prioridade retorna os maiores elementos primeiro, os elementos que "vêm antes" acabam sendo retornados por último. Ou seja, a frente da fila contém o "último" elemento de acordo com o ordenamento fraco Compare. |
[editar] Tipos membros
Tipo membro | Definição |
container_type
|
Container
|
value_type
|
Container::value_type
|
size_type
|
Container::size_type
|
reference
|
Container::reference
|
const_reference
|
Container::const_reference
|
[editar] Funções membros
constrói o priority_queue Original: constructs the priority_queue The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
destrói o priority_queue Original: destructs the priority_queue The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
atribui valores ao adaptador de recipiente Original: assigns values to the container adaptor The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
Acesso aos Elementos | |
acessar o elemento superior Original: access the top element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
Capacidade | |
verifica se o recipiente subjacente está vazio Original: checks whether the underlying container is empty The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
devolve o número de elementos Original: returns the number of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
Modificadores | |
inserts element and sorts the underlying container (função pública membro) | |
(C++11) |
constructs element in-place and sorts the underlying container (função pública membro) |
remove o primeiro elemento Original: removes the first element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
Trocar o conteúdo Original: swaps the contents The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
Objetos Membros | |
Container c |
o recipiente subjacente Original: the underlying container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (objeto protegido membro) |
Compare comp |
o objeto função de comparação (objeto protegido membro) |
[editar] Funções não-membros
o algoritmo especializado std::swap Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (modelo de função) |
[editar] Classes auxiliares
especializa o traço tipo std::uses_allocator Original: specializes the std::uses_allocator type trait The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (modelo de função) |