std::stable_partition
De cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| Dclar dans l'en-tte <algorithm>
|
||
template< class BidirIt, class UnaryPredicate > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p ); |
||
Rordonne les lments de la gamme
[first, last) de telle manire que tous les lments pour lesquels le prdicat renvoie p true prcder les lments pour lesquels prdicat retourne p false. Ordre relatif des lments est conserv . 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.
Paramtres
| first, last | - | l'ventail d'lments rorganiser
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 | - | prdicat unaire qui retourne true si l'lment doit tre command avant autres lments . 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. L'expression |
| Type requirements | ||
-BidirIt must meet the requirements of ValueSwappable and BidirectionalIterator.
| ||
-The type of dereferenced BidirIt must meet the requirements of MoveAssignable and MoveConstructible.
| ||
Retourne la valeur
Itrateur sur le premier lment du second groupe
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.
Complexit
Exactement
last-first applications du prdicat et la plupart des swaps (last-first)*log(last-first) s'il n'y a pas assez de mmoire ou de nombre linaire de swaps si la mmoire disponible est suffisante .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.
Exemple
#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';
}
Rsultat :
3 2 4 5 7 0 0 0 0
Voir aussi
divise une srie d'lments en deux groupes Original: divides a range of elements into two groups The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction gnrique) | |