-
Notifications
You must be signed in to change notification settings - Fork 2
/
51.cpp
51 lines (44 loc) · 1.17 KB
/
51.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<set>
#include<algorithm>
int main()
{
//program to demonstrate the multiset of the STL container
std::multiset<int> m;
//adding elements to the multiset
m.insert(4);
m.insert(1);
m.insert(5);
m.insert(22);
m.insert(42);
m.insert(3);
//printing the multiset
std::cout<<"Multi set : \n";
std::multiset<int>::iterator it;
for(it = m.begin();it!=m.end();it++)
{
std::cout<<*it<<" ";
}
std::cout<<std::endl;
//deleting 5 from the multiset
std::cout<<"Deleting 5 from the multi set...!"<<std::endl;
m.erase(5);
//finding 4 in the multiset
std::cout<<"Finding 5 in the multi set...!"<<std::endl;
if(m.find(5)!=m.end())
{
std::cout<<"Element found!"<<std::endl;
}
else
{
std::cout<<"Element not found!!"<<std::endl;
}
//size of the multiset
std::cout<<"Size of the multi set : "<<m.size()<<std::endl;
//counting elements with a specific key
std::cout<<"Count of 3 : "<<m.count(3)<<std::endl;
//first element of the multiset
it = m.begin();
std::cout<<"First element : "<<*it<<std::endl;
return 0;
}