• Both algorithms move all elements in the range [beg,end) to the front, for which the unary predicate op(elem) yields true. • Both algorithms return the first position for which op() yields false. • The difference between partition() and stable_partition() is that the algorithm stable_partition() preservestherelativeorderofelementsthatmatchthecriterionandthose that do not. • You could use this algorithmto split elementsintotwo parts accordingto a sortingcriterion. The nth_element() algorithm has a similar ability. See Section 11.2.2, page 514, for a discussion of the differences between these algorithms and nth_element(). • Note that op should not change its state during a function call. See Section 10.1.4, page 483, for details. • Before C++11, partition() required bidirectional iterators instead of forward iterators and guaranteed at most numElems/2 swaps. • Use partition_copy() (see Section 11.8.6, page 594) to copy elements into one destination range for fulfilling and one for not fulfilling a predicate (available since C++11). • Complexity: – Forpartition(): linear(atmostnumElems/2swapsandnumElemscallsofop()ifbidirec- tional iterators or random-access iterators are used; at most numElems swaps if the iterators are only forward iterators). – For stable_partition(): linear if there is enough extra memory (numElems swaps and calls of op()); otherwise, n-log-n (numElems calls of op() but numElems*log(numElems) swaps). The following program demonstrates the use of and the difference between partition() and stable_partition():