티스토리 뷰

데이터베이스

[C++] vector pair 정렬하기

waterground 2020. 1. 26. 14:19

1. 첫번째 원소 기준으로 정렬

bool compare(const pair<int, int> &a, const pair<int, int> &b){
	return a.first < b.first;
}

 

 

2. 두번째 원소 기준으로 정렬

bool compare(const pair<int, int> &a, const pair<int, int> &b){
	return a.second < b.second;
}

 

 

사용시

sort(v.begin(), v.end(), compare);
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함