cpp/algorithm/nth element

is a partial sorting algorithm that rearranges elements in such that:


 * The element pointed at by is changed to whatever element would occur in that position if  were sorted.
 * All of the elements before this new element are less than or equal to the elements after the new  element.

More formally, partially sorts the range  in ascending order so that the condition  (for, or  for ) is met for any  in the range  and for any  in the range. The element placed in the position is exactly the element that would occur in this position if the range was fully sorted.

may be the end iterator, in this case the function has no effect.

@1@ Elements are compared using. @3@ Elements are compared using the given binary comparison function. @2,4@ Same as, but executed according to.

Return value
(none)

Complexity
@1,3@ Linear in on average. @2,4@ O(N) applications of the predicate, and O(N log N) swaps, where.

Possible implementation
See also the implementations in libstdc++, libc++, and msvc stl.