fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. bool less_than(int a, int b) { return a <b;}
  5. int main()
  6. {
  7. std::vector<std::vector<double>> vector1 = {{4,3,5,3},
  8. {2,6,3,7},
  9. {6,8,5,1},
  10. {5,6,1,5}};
  11.  
  12. int i = 3;
  13. std::sort(vector1.begin(),
  14. vector1.end(),
  15. [i] (const std::vector<double> &a, const std::vector<double> &b)
  16. {
  17. return less_than(a[i] , b[i]);
  18. });
  19.  
  20. for (auto &r : vector1)
  21. {
  22. for (auto e : r)
  23. std::cout << e << " ";
  24. std::cout << std::endl;
  25. }
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
6 8 5 1 
4 3 5 3 
5 6 1 5 
2 6 3 7