데이터베이스

[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);