Advertisement
maycod23

Multiset_Cpp

Jul 10th, 2022
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. # include   <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6.     ll t = 1;
  7.     // cin >> t;
  8.     while (t--)
  9.     {
  10.         // multiset<ll> m1; //store in ascending order
  11.  
  12.         // m1.insert(10); m1.insert(20); m1.insert(1); m1.insert(10);
  13.         // for (auto i : m1) cout << i << " "; cout << endl;
  14.  
  15.         // cout << m1.count(10) << endl;//frequency of 10
  16.  
  17.         // m1.erase(10);//erased all instances/occurences of 10
  18.         // for (auto i : m1) cout << i << " "; cout << endl;
  19.  
  20.         // m1.insert(10); m1.insert(10);
  21.         // for (auto i : m1) cout << i << " "; cout << endl;
  22.  
  23.         // m1.erase(m1.find(10));//erased only single instance of 10
  24.         // for (auto i : m1) cout << i << " "; cout << endl;
  25.  
  26.         // auto it1 = m1.begin();
  27.         // cout << *it1 << endl << endl << endl; //or*m1.begin()
  28. ///////////////////////////////////////////////////////////////////////////////////////
  29.  
  30.         multiset<ll, greater<ll>> m2; //store in descending order
  31.  
  32.         m2.insert(10); m2.insert(20); m2.insert(1); m2.insert(10);
  33.         for (auto i : m2) cout << i << " "; cout << endl;
  34.  
  35.         cout << m2.count(10) << endl;//ferqeuency of 10
  36.  
  37.         m2.erase(10);//erased all instances of 10
  38.         for (auto i : m2) cout << i << " "; cout << endl;
  39.  
  40.         m2.insert(10); m2.insert(10);
  41.         for (auto i : m2) cout << i << " "; cout << endl;
  42.  
  43.         m2.erase(m2.find(10));//erased only single instance of 10
  44.         for (auto i : m2) cout << i << " "; cout << endl;
  45.  
  46.         auto it2 = m2.begin();
  47.         cout << *it2 << endl;//or*m2.begin()
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement