title: What's the most efficient way to extract min, max & median from a vector
body: <p>Given a <code>vector&lt;T&gt; vec{...}</code> what's the best way to extract its minimum, maximum and median assuming T is one of the numeric types? I know of <a href="https://en.cppreference.com/w/cpp/algorithm/nth_element" rel="noreferrer"><code>std::nth_element</code></a> as well as <a href="https://en.cppreference.com/w/cpp/algorithm/minmax_element" rel="noreferrer"><code>std::minmax_element</code></a> but they seem to do redundant work if called one after another.</p>
  
  <p>The best idea I came up with so far is to just call std::nth_element 3 times one after another. But this still needs 3N comparisons, right? Is there any way to reuse the partial sorting done in previous iterations?</p>