fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. struct Node
  6. {
  7. int x;
  8. int y;
  9. float value;
  10. };
  11.  
  12. int main() {
  13. std::vector<Node> vec {
  14. {5, 6, 0.f}, {2, 4, 0.f}, {1, 1, 0.f}, {1, 0, 0.f}, {8, 10, 0.f}, {4, 7, 0.f},
  15. {7, 1, 0.f}, {5, 4, 0.f}, {6, 1, 0.f}, {1, 4, 0.f}, {3, 10, 0.f}, {7, 2, 0.f}
  16. };
  17.  
  18. std::sort(std::begin(vec), std::end(vec), [](const Node& a, const Node& b) {
  19. return a.y < b.y || (a.y == b.y && a.x < b.x);
  20. });
  21.  
  22. std::cout << "x y" << std::endl << std::endl;
  23. for (auto const &n : vec)
  24. std::cout << n.x << " " << n.y << std::endl;
  25. }
  26.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
x y

1 0
1 1
6 1
7 1
7 2
1 4
2 4
5 4
5 6
4 7
3 10
8 10