fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. double f(const std::vector<double> &arr, bool maxElem) {
  6. using iterator = decltype(arr.begin());
  7. auto me = maxElem ? &std::max_element<iterator> : &std::min_element<iterator>;
  8. return *me(arr.begin(), arr.end());
  9. }
  10.  
  11. int main() {
  12. std::vector<double> v{1, 2, 0, 3, 1, 4, 42, 1, 2};
  13. std::cout << f(v, true) << std::endl;
  14. std::cout << f(v, false) << std::endl;
  15. return 0;
  16. }
Success #stdin #stdout 0s 4544KB
stdin
Standard input is empty
stdout
42
0