Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<vector>
- #include<iostream>
- #include <algorithm>
- using namespace std;
- bool cmp1_stable(const pair<int,int> &a, const pair<int,int> &b){
- return a.first<b.first;
- }
- bool cmp2_unstable(const pair<int,int> &a, const pair<int,int> &b)
- {
- if(a.first!=b.first)
- return a.first < b.first;
- else
- return a.second > b.second;
- }
- int main(){
- vector<pair<int,int>> arr = {{4,0},{3,1},{2,2},{2,3},{2,4}};
- sort(arr.begin(),arr.end(),cmp1_stable);//cmp2_unstable
- for(int i=0;i<5;++i){
- cout<<arr[i].first<<" "<<arr[i].second<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment