nth_element

Syntax:

    #include <algorithm>
    void nth_element( iterator start, iterator nth, iterator end );
    void nth_element( iterator start, iterator nth, iterator end, StrictWeakOrdering cmp );

The nth_element() function semi-sorts the range of elements defined by [start,end). It puts the element of the range to the nth position, that would be there, if the entire range was sorted, and it makes sure that none of the elements before that element are greater than any of the elements that come after that element.

nth_element() runs in linear time on average.

Related Topics: partial_sort