C++ STL
vector<pair<int, int> > v; 정렬하는 방법
parkit
2018. 11. 28. 21:26
728x90
반응형
vector<pair<int, int> > v;
정렬
< : 오름차순
> : 내림차순
참고로 cmp 함수 없이 sort(v.begin(), v.end())로 해주면, first를 기준으로 정렬된다.
first를 기준으로 정렬할 때에는
1 2 3 4 | bool cmp(const pair<int, int> &a, const pair<int, int> &b) { return a.first < b.first; } | cs |
second를 기준으로 정렬할 때에는
1 2 3 4 | bool cmp(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; } | cs |
728x90
반응형