fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5.  
  6. bool cmp(const int& lhs, const int& rhs)
  7. {
  8. return lhs < rhs;
  9. }
  10.  
  11. void print(const std::vector<int>& v)
  12. {
  13. for(auto n : v)
  14. {
  15. std::cout << n << " ";
  16. }
  17. std::cout << "\n";
  18. }
  19.  
  20. int main()
  21. {
  22. std::vector<int> v = {1,3,9,3,7,5,8,2,4};
  23. print(v);
  24. std::sort(v.begin(), v.end(), cmp);
  25. print(v);
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 3 9 3 7 5 8 2 4 
1 2 3 3 4 5 7 8 9