Lexicographical order

Vector를 축 기준으로 정렬 할 때 사용 한 방법.

struct Vector2 { float x, y; }

std::vector<Vector2> points;

points.push_back(Vector2(1, 2));
...

std::sort(points.begin(), points.end(), [](const Vector2& v0, const Vector2& v1)
{
       return v0.x < v1.x || (v0.x == v1.x && v0.y < v1.y);
});

x축 먼저 확인 한 다음 두 값이 같다면 y축을 기준으로 정렬한다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다