Advertisement
apl-mhd

pair of vector sort

May 5th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <utility>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. bool compare(const pair<int, int> i, const pair<int, int> j)
  10. {
  11.     return  j.first > i.first ;
  12. }
  13.  
  14.  
  15.  
  16. int main() {
  17.  
  18.     vector<pair<int, int>> v;
  19.  
  20.     v.push_back(make_pair(10,100));
  21.     v.push_back(make_pair(9,2));
  22.     v.push_back(make_pair(8,3));
  23.     v.push_back(make_pair(7,4));
  24.     v.push_back(make_pair(6,500));
  25.  
  26.  
  27.  
  28.  
  29.  
  30.     sort(v.begin(),v.end(),compare);
  31.  
  32.     vector<pair<int,int>>::iterator it;
  33.  
  34.     for( it = v.begin(); it!=v.end(); it++){
  35.  
  36.         cout<<it->first<<" "<<it->second<<endl;
  37.  
  38.     }
  39.  
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement