fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. int main()
  6. {
  7. int v[] = {1,2,3,4,5,4};
  8.  
  9. auto[a, b] = std::minmax_element(std::begin(v), std::end(v));
  10. std::swap(*a, *b);
  11.  
  12. for (const auto x: v)
  13. { std::cout << x << ' ';
  14. }
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 5440KB
stdin
Standard input is empty
stdout
5 2 3 4 1 4