#include<bits/stdc++.h>
using namespace std;
int main()
{
multiset<int> ms;
multiset<int> :: iterator it;
multiset<int> :: iterator ir;
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
cout << "Multiset Size :: " << ms.size() << "\n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
it = ms.begin();
ms.erase(it);
cout << "\nAfter Erase One Element :: \n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
int n = ms.erase(1);
cout << "\nRemove Item :: " << n << "\n";
cout << "\nAfter Erase all 1 Element :: \n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
ms.insert(1);
ms.insert(2);
ms.insert(3);
ms.insert(4);
ms.insert(5);
ms.insert(6);
ms.insert(7);
ms.insert(8);
ms.insert(9);
ms.insert(10);
ms.insert(11);
ms.insert(12);
ms.insert(13);
ms.insert(14);
it = ms.begin();
it++;
it++;
it++;
ir = ms.end();
ir--;
ir--;
ir--;
ir--;
ms.erase(it, ir);
cout << "\nAfter Erase Element :: \n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
return 0;
}
using namespace std;
int main()
{
multiset<int> ms;
multiset<int> :: iterator it;
multiset<int> :: iterator ir;
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
ms.insert(1);
cout << "Multiset Size :: " << ms.size() << "\n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
it = ms.begin();
ms.erase(it);
cout << "\nAfter Erase One Element :: \n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
int n = ms.erase(1);
cout << "\nRemove Item :: " << n << "\n";
cout << "\nAfter Erase all 1 Element :: \n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
ms.insert(1);
ms.insert(2);
ms.insert(3);
ms.insert(4);
ms.insert(5);
ms.insert(6);
ms.insert(7);
ms.insert(8);
ms.insert(9);
ms.insert(10);
ms.insert(11);
ms.insert(12);
ms.insert(13);
ms.insert(14);
it = ms.begin();
it++;
it++;
it++;
ir = ms.end();
ir--;
ir--;
ir--;
ir--;
ms.erase(it, ir);
cout << "\nAfter Erase Element :: \n";
for(it=ms.begin(); it!=ms.end(); it++)
cout << *it << " ";
cout << "\n";
return 0;
}
Comments
Post a Comment