[ Web Proxy ]
URL:
Viewing: http://es.cppreference.com/cpp/algorithm/is_heap [Back]  [Original]

std::is_heap - cppreference.com
cppreference.com
Espacios de nombres
Variantes

std::is_heap

De cppreference.com
 
 
Biblioteca de algoritmos
Polticas de ejecucin (C++17)
Operaciones de secuencia no modificantes
(C++11)(C++11)(C++11)
(C++17)
Operaciones de secuencia modificantes
Operaciones en almacenamiento no inicializado
Operaciones de particin
Operaciones de ordenacin
(C++11)
Operaciones de bsqueda binaria
Operaciones de conjuntos (en rangos ordenados)
Operaciones de pila
(C++11)
Operaciones mnimo/mximo
(C++11)
(C++17)
Permutaciones
Operaciones numricas
Bibliotecas C
 
Definido en el archivo de encabezado <algorithm>
template< class RandomIt >
bool is_heap( RandomIt first, RandomIt last );
(1)
template< class RandomIt, class Compare >
bool is_heap( RandomIt first, RandomIt last, Compare comp );
(2)
Comprueba si los elementos en el rango [first, last) son un montn' .
Original:
Checks if the elements in range [first, last) are a heap.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
La primera versin de is_heap operator< utiliza para comparar elementos, mientras que el segundo utiliza la funcin de comparacin dado comp .
Original:
The first version of is_heap uses operator< to compare elements, whereas the second uses the given comparison function comp.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parmetros

first, last -
la gama de elementos a examinar
Original:
the range of elements to examine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
comp - objeto funcin de comparacin (es decir, un objeto que satisface los requerimientos de Compare) que devuelve true si el primer argumento es menor que el segundo.

La signatura de la funcin de comparacin deber ser equivalente a lo siguiente:

bool cmp(const Type1 &a, const Type2 &b);

Mientras que la signatura no necesita ser const &, la funcin no debe modificar los objetos que se le pasaron y debe admitir todos los valores de los tipos (posiblemente const) Type1 y Type2 a pesar de la categora de valor (por consiguiente, no se permite a Type1 & , ni tampoco a Type1 a menos que para Type1 un movimiento sea equivalente a una copia (desde C++11)).
Los tipos Type1 y Type2 deben ser tales que un objeto de tipo RandomIt puede ser desreferenciado y luego convertido implcitamente a ambos.

Requisitos de tipo
-
RandomIt debe reunir los requerimientos de RandomAccessIterator.

Valor de retorno

true si el rango es montn', false lo contrario .
Original:
true if the range is heap, false otherwise.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complejidad

Lineal en la distancia entre first y last
Original:
Linear in the distance between first and last
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Notas

Un montn' es una serie de elementos [f,l) que tiene las siguientes propiedades:
Original:
A heap is a range of elements [f,l) that has the following properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • *f es el elemento ms grande en el intervalo
    Original:
    *f is the largest element in the range
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • un elemento nuevo puede aadirse utilizando std::push_heap()
    Original:
    a new element can be added using std::push_heap()
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • el primer elemento se puede eliminar con std::pop_heap()
    Original:
    the first element can be removed using std::pop_heap()
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
La disposicin real de los elementos depende de la implementacin .
Original:
The actual arrangement of the elements is implementation defined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Ejemplo

#include <iostream>
#include <algorithm>

int main()
{
    std::vector<int> v { 3, 1, 4, 1, 5, 9 };

    std::cout << "initially, v: ";
    for (auto i : v) std::cout << i << ' ';
    std::cout << '\n';

    if (!std::is_heap(v.begin(), v.end())) {
        std::cout << "making heap...\n";
        std::make_heap(v.begin(), v.end());
    }

    std::cout << "after make_heap, v: ";
    for (auto i : v) std::cout << i << ' ';
    std::cout << '\n';
}

Salida:

initially, v: 3 1 4 1 5 9 
making heap...
after make_heap, v: 9 5 4 1 1 3

Ver tambin

Encuentra el subrango ms grande que es un montculo de mximos.
(plantilla de funcin) [editar]

Web Proxy Viewer  |  New URL  |  Original Page