std::stable_partition
De cppreference.com
<metanoindex/>
<tbody> </tbody>| Definido no cabeçalho <algorithm>
|
||
template< class BidirIt, class UnaryPredicate > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p ); |
||
Reordena os elementos na
[first, last) faixa, de tal modo que todos os elementos para os quais o predicado p retornos true precedem os elementos para os quais predicado p retornos false. Ordem relativa dos elementos é preservada. 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.
You can help to correct and verify the translation. Click here for instructions.
Parâmetros
| first, last | - | a gama de elementos para reordenar
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 | - | unary predicate which returns true se o elemento deve ser solicitado antes de outros 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. The signature of the predicate function should be equivalent to the following:
The signature does not need to have |
| Type requirements | ||
-BidirIt must meet the requirements of ValueSwappable and BidirectionalIterator.
| ||
-The type of dereferenced BidirIt must meet the requirements of MoveAssignable and MoveConstructible.
| ||
Valor de retorno
Iterador para o primeiro elemento do 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.
You can help to correct and verify the translation. Click here for instructions.
Complexidade
Exatamente
last-first aplicações do predicado e em swaps maioria (last-first)*log(last-first) Se não houver memória insuficiente ou número linear de swaps se a memória suficiente disponível.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.
You can help to correct and verify the translation. Click here for instructions.
Exemplo
#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';
}
Saída:
3 2 4 5 7 0 0 0 0
