Created
December 26, 2016 15:57
-
-
Save momchil-velikov/733dde3bebb9dcac22953c6b54f74800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <tuple> | |
#include <vector> | |
struct S { | |
int x, y, z; | |
}; | |
int main() { | |
std::vector<S> a = { | |
{1, 2, 3}, | |
{1, 2, 4}, | |
{1, 3, 4}, | |
{1, 3, 1}, | |
{2, 2, 3}, | |
{3, 1, 1}, | |
}; | |
std::sort(begin(a), end(a), | |
[](const S &a, const S &b) -> bool { | |
return std::tie(a.x, b.y, a.z) < std::tie(b.x, a.y, b.z); | |
}); | |
for (const auto &e : a) | |
std::cout << e.x << " " << e.y << " " << e.z << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment