Skip to content

Instantly share code, notes, and snippets.

@mochow13
Created September 18, 2018 14:45
Show Gist options
  • Save mochow13/462c9721043456b2419b5a102ad8e44a to your computer and use it in GitHub Desktop.
Save mochow13/462c9721043456b2419b5a102ad8e44a to your computer and use it in GitHub Desktop.
int a=9, b=12;
// out.first contains the minimum element, out.second is the maximum one
auto out=std::minmax(a,b);
std::vector<int> collection={6,5,3,2,1,4,6,7};
auto result=std::minmax_element(begin(collection), end(collection));
// you can also add compare function as the third argument
// (result.first - collection.begin()) is the index of the minimum element
// (result.second - collection.begin()) is the index of the maximum element
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment