std::stable_partition
Aus cppreference.com
< cpp | algorithm
Version vom 22. Oktober 2012, 15:48 Uhr von TranslationBot (Diskussion | Beiträge)
Defined in header <algorithm>
|
||
template< class BidirIt, class UnaryPredicate > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p ); |
||
Ordnet die Elemente im Bereich
[first, last)
derart, daß alle Elemente für die das Prädikat p
kehrt true vorausgehen, für die die Elemente Prädikats p
kehrt false. Relative Reihenfolge der Elemente erhalten ist . 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.
Inhaltsverzeichnis |
Parameter
first, last | - | der Bereich von Elementen neu zu ordnen
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 wenn das Element sollte vor anderen Elementen bestellt werden . 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 const &, but the function must not modify the objects passed to it. | |||||||||
Type requirements | |||||||||||
-BidirIt must meet the requirements of ValueSwappable and BidirectionalIterator .
| |||||||||||
-The type of dereferenced BidirIt must meet the requirements of MoveAssignable and MoveConstructible .
|
Rückgabewert
Iterator das erste Element der zweiten Gruppe
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.
Komplexität
Genau
last-first
Anwendungen des Prädikats und höchstens (last-first)*log(last-first)
Swaps, wenn es nicht genügend Arbeitsspeicher oder lineare Anzahl von Swaps, wenn genügend Speicherplatz vorhanden ist .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.
Beispiel
#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'; }
Output:
3 2 4 5 7 0 0 0 0