fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. bool mySort(int x, int y)
  8. {
  9. if (x % 10 != y % 10) return (x % 10 < y % 10);
  10. return x < y;
  11. }
  12.  
  13. int main()
  14. {
  15. vector<int> myVector;
  16.  
  17. myVector.push_back(12);
  18. myVector.push_back(15);
  19. myVector.push_back(43);
  20. myVector.push_back(13);
  21. myVector.push_back(20);
  22. myVector.push_back(1);
  23. myVector.push_back(15);
  24.  
  25. for (vector<int>::iterator it = myVector.begin(); it != myVector.end(); it++)
  26. cout << *it << endl;
  27.  
  28. cout << endl;
  29.  
  30. sort(myVector.begin(), myVector.end(), mySort);
  31.  
  32. for (vector<int>::iterator it = myVector.begin(); it != myVector.end(); it++)
  33. cout << *it << endl;
  34.  
  35. system("pause");
  36. return 0;
  37. }
Success #stdin #stdout #stderr 0s 4336KB
stdin
Standard input is empty
stdout
12
15
43
13
20
1
15

20
1
12
13
43
15
15
stderr
sh: 1: pause: not found