Skip to content

Instantly share code, notes, and snippets.

@danlark1
Last active April 13, 2022 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlark1/9e3216cad1dc854c56b9cace1dd87677 to your computer and use it in GitHub Desktop.
Save danlark1/9e3216cad1dc854c56b9cace1dd87677 to your computer and use it in GitHub Desktop.
std::vector<int> values = { /* more than 10 values */ };
std::nth_element(values.begin(), values.begin() + 9, values.end());
int tenth_element = values[9];
std::vector<int> values = { /* more than 10 values */ };
std::partial_sort(values.begin(), values.begin() + 10, values.end());
int tenth_element = values[9];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment