Skip to content

Instantly share code, notes, and snippets.

@mochow13
Created September 15, 2018 06:01
Show Gist options
  • Save mochow13/6dc0b1beb93568dea42fcf85befb2024 to your computer and use it in GitHub Desktop.
Save mochow13/6dc0b1beb93568dea42fcf85befb2024 to your computer and use it in GitHub Desktop.
std::vector<int> collection={1,2,13,5,12,3,4};
auto median_pos=collection.begin()+collection.size()/2;
std::nth_element(begin(collection),median_pos,end(collection));
// note that the original vector will be changed due to the operations
// done by nth_element
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment