std::stable_partition
Da cppreference.com.
![]() | Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Defined in header <algorithm> | ||
template<class BidirIt, class UnaryPredicate > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPredicate p ); | ||
Riordina gli elementi nel
[first, last)
gamma in modo tale che tutti gli elementi per cui il predicato p
rendimenti true precedere gli elementi per i quali predicato p
rendimenti false. Ordine relativo degli elementi viene mantenuto. 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.
Indice |
[modifica]Parametri
first, last | - | la gamma di elementi da riordinare 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 l'elemento deve essere ordinato prima di altri elementi . 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: bool pred(const Type &a); 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 . |
[modifica]Valore di ritorno
Iteratore al primo elemento del secondo gruppo
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.
[modifica]Complessità
Esattamente
last-first
applicazioni del predicato e la maggior parte delle operazioni di swap (last-first)*log(last-first)
se non vi è memoria insufficiente o numero lineare di swap se la memoria disponibile è sufficiente.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.
[modifica]Esempio
#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
[modifica]Vedi anche
divide una serie di elementi in due gruppi 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. (funzione di modello) |