Advertisement
apl-mhd

new for loop

May 5th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <utility>
  5.  
  6. #include <queue>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. bool compare( pair<int, int> i,  pair<int, int> j)
  12. {
  13.     return  j.first > i.first ;
  14. }
  15.  
  16.  
  17.  
  18. int main() {
  19.  
  20.  
  21.     int a [] = {1,2,3,4};
  22.  
  23.     for(int n : a)
  24.         cout<<n<<" ";
  25.  
  26.  
  27.     cout<<endl;
  28.  
  29.  
  30.     priority_queue<int, vector<int>, greater<int>>q;
  31.  
  32.  
  33.  
  34.     q.push(10);
  35.     q.push(9);
  36.     q.push(18);
  37.  
  38.     cout<<"Q sort"<<endl;
  39.  
  40.  
  41.     while(!q.empty()){
  42.  
  43.         cout<<q.top()<<" ";
  44.  
  45.         q.pop();
  46.     }
  47.  
  48.  
  49.  
  50.  
  51.     cout<<"\nvector pair\n";
  52.  
  53.  
  54.  
  55.     vector<pair<int, int>> v;
  56.  
  57.     v.push_back(make_pair(10,100));
  58.     v.push_back(make_pair(9,2));
  59.     v.push_back(make_pair(8,3));
  60.     v.push_back(make_pair(7,4));
  61.     v.push_back(make_pair(6,500));
  62.  
  63.  
  64.  
  65.     sort(v.begin(),v.end(),compare);
  66.  
  67.     vector<pair<int,int>>::iterator it;
  68.  
  69.     for( it = v.begin(); it!=v.end(); it++){
  70.  
  71.         cout<<it->first<<" "<<it->second<<endl;
  72.  
  73.     }
  74.  
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement