-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmultiset implementation.cpp
61 lines (49 loc) · 1.84 KB
/
multiset implementation.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
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include<set>
//typedef multiset<int>::iterator It
using namespace std;
typedef multiset<int>::iterator It;
int main()
{
int arr[]={10,12,20,22,23,22,45,56,33,33,33,33,33,33,33};
int n= sizeof(arr)/sizeof(int);
// inserting into multiset
multiset<int> m(arr,arr+n);
//iterating over all element
for(int x:m)
{
cout<<x<<" : ";
}cout<<endl;
//erasing a particular element
m.erase(33);
for(int x:m)
{
cout<<x<<" : ";
}cout<<endl;
//inserting an element
m.insert(77);
for(int x:m)
{
cout<<x<<" : ";
}cout<<endl;
//count the occurance of element
cout<<m.count(33);
//to get a iterate at a particular element
auto it=m.find(33);
cout<<(*it)<<"->";
cout<<endl;
// to print all accurance of a given number
pair<It,It>range=m.equal_range(30);
for(auto it= range.first;it!=range.second;it++)
{
cout<<*it<<"-";
}
//we have to define iterator before main()
//typedef multiset<int>::iterator It
//lower bound and upper bound
for(auto it = m.lower_bound(10);it!=m.upper_bound(60);it++)
{
cout<<*it<<" - ";
}
return 0;
}