Nth Element Guarantees
The standard says that after nth_element, the element at nth is the one that would be there if the whole range were sorted, and that for every i in [first, nth) and j in [nth, last), comp(*j, *i) is false.
std::vector<int> v = {9, 1, 8, 2, 7, 3, 6, 4, 5};
std::nth_element(v.begin(), v.begin() + 3, v.end());
Which statement is guaranteed?
Sign in to answer questions and track your progress
Sign In