fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. struct Vector3D
  8. {
  9. float x,y,z;
  10. };
  11.  
  12. bool operator < (const Vector3D& a, const Vector3D& b)
  13. {
  14. if (a.x < b.x) return true;
  15. if (a.x > b.x) return false;
  16.  
  17. if (a.y < b.y) return true;
  18. if (a.y > b.y) return false;
  19.  
  20. if (a.z < b.z) return true;
  21. if (a.z > b.z) return false;
  22.  
  23. return false;
  24. }
  25.  
  26.  
  27. int main(int argc, char * argv[])
  28. {
  29.  
  30. vector<Vector3D> v = {
  31. {-0.5, -0.5, -0.5},
  32. {0.0, -0.5, -0.5},
  33. {0.5, -0.5, -0.5},
  34.  
  35. {0.5, -0.5, 0.0},
  36. {0.5, -0.5, 0.5},
  37. {0.0, -0.5, 0.5},
  38.  
  39. {-0.5, -0.5, 0.5},
  40. {-0.5, -0.5, 0.0}
  41. };
  42.  
  43. sort(v.begin(),v.end());
  44.  
  45. for(int i = 0; i < v.size(); ++i)
  46. cout << v[i].x << " " << v[i].y << " " << v[i].z << endl;
  47.  
  48. }
  49.  
Success #stdin #stdout 0.01s 5448KB
stdin
Standard input is empty
stdout
-0.5  -0.5  -0.5
-0.5  -0.5  0
-0.5  -0.5  0.5
0  -0.5  -0.5
0  -0.5  0.5
0.5  -0.5  -0.5
0.5  -0.5  0
0.5  -0.5  0.5