vector<pair<type, type> > 람다 이용해서 정렬하기
2019. 9. 1. 13:12
프로그래밍 언어/C++
단일 vector만 사용했다면 sort()를 사용해서 정렬할 수 있다. 하지만 vector 와 pair를 같이 사용했을 때에는 람다나 비교 함수를 사용해서 정렬을 해주어야한다. 지금은 람다를 이용해서 정렬하는 경우다. #include #include vector v; // first 로 정렬하기 sort(v.begin(), v.end(), [](const pair &a, const pair &b) { return a.first > b.first; }); // second 로 정렬하기 sort(v.begin(), v.end(), [](const pair &a, const pair &b) { return a.second > b.second; });