◐ Shell
clean mode source ↗

std::stable_partition - cppreference.com

De cppreference.com

Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.

La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí.

Definido en el archivo de encabezado <algorithm>

template< class BidirIt, class UnaryPredicate > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p );

Reordena los elementos de la [first, last) rango de tal manera que todos los elementos para los que el predicado p vuelve true preceder a los elementos para los que predicado p vuelve false. Orden relativo de los elementos se conserva .

Original:

Reorders the elements in the range [first, last) in such a way that all elements for which the predicate p returns true precede the elements for which predicate p returns false. Relative order of the elements is preserved.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parámetros

first, last -

la gama de elementos a ordenar

Original:

the range of elements to reorder

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

p - Predicado unario que devuelve ​true

si el elemento debe pedirse antes de otros elementos

Original:

if the element should be ordered before other elements

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

.

La expresión p(v) debe ser convertible a bool para cada argumento v de tipo (posiblemente const) VT, donde VT es el tipo valor de BidirIt, independientemente de la categoría de valor, y no debe modificar v. Por lo tanto, no se admite un parámetro de tipo VT&, ni es VT a menos que para VT una operación de movimiento sea equivalente a una copia (desde C++11). ​

Requisitos de tipo
-BidirIt debe reunir los requerimientos de ValueSwappable y BidirectionalIterator.
-The type of dereferenced BidirIt must meet the requirements of MoveAssignable and MoveConstructible.

Valor de retorno

Iterador al primer elemento del segundo grupo

Original:

Iterator to the first element of the second group

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Complejidad

Exactamente last-first aplicaciones del predicado y en la mayoría de los swaps (last-first)*log(last-first) si no hay suficiente memoria o el número lineal de las permutas si hay suficiente memoria disponible .

Original:

Exactly last-first applications of the predicate and at most (last-first)*log(last-first) swaps if there is insufficient memory or linear number of swaps if sufficient memory is available.

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{0, 0, 3, 0, 2, 4, 5, 0, 7};
    std::stable_partition(v.begin(), v.end(), [](int n){return n>0;});
    for (int n : v) {
        std::cout << n << ' ';
    }
    std::cout << '\n';
}

Salida:

Ver también

Divide un rango de elementos en dos grupos.
(plantilla de función) [editar]