aj30

Untitled

Oct 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include<vector>
  2. #include<iostream>
  3. #include <algorithm>
  4. using namespace std;
  5. bool cmp1_stable(const pair<int,int> &a, const pair<int,int> &b){
  6. return a.first<b.first;
  7. }
  8. bool cmp2_unstable(const pair<int,int> &a, const pair<int,int> &b)
  9. {
  10. if(a.first!=b.first)
  11. return a.first < b.first;
  12. else
  13. return a.second > b.second;
  14. }
  15. int main(){
  16.  
  17. vector<pair<int,int>> arr = {{4,0},{3,1},{2,2},{2,3},{2,4}};
  18. sort(arr.begin(),arr.end(),cmp1_stable);//cmp2_unstable
  19. for(int i=0;i<5;++i){
  20. cout<<arr[i].first<<" "<<arr[i].second<<endl;
  21. }
  22.  
  23. return 0;
  24. }
Add Comment
Please, Sign In to add comment