std::stable_partition animation

with manim


Additional Memory → In-Place →


Function definition

                
template< class BidirIterator, class UnaryPredicate >
BidirIterator stable_partition( BidirIterator first, BidirIterator last, UnaryPredicate p );
                
            
Effect

std::stable_partition 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.

Return

Iterator to the first element of the second group

Complexity

Given N = std::distance(first, last),

  1. Exactly N applications of the predicate and O(N) swaps if there is enough extra memory. If memory is insufficient, at most N log N swaps.
  2. O(N log N) swaps and O(N) applications of the predicate


Additional Memory

std::stable_parition additional memory

In-Place

std::stable_parition in-place