-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmultisets.cpp
More file actions
61 lines (57 loc) · 1.72 KB
/
multisets.cpp
File metadata and controls
61 lines (57 loc) · 1.72 KB
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<bits/stdc++.h>
using namespace std;
int main()
{
int n,temp;
cout<<"enter number of elements:"<<endl;
cin>>n;
multiset<int,less<int>> ms;
//input demonstration
for(int o=0;o<n;o++)
{
cout<<"enter "<<"element "<<(o+1)<<":"<<endl;
cin>>temp;
ms.insert(temp);
}
//iterator for printing elements
multiset<int,less<int>>::iterator it;
for(it=ms.begin();it!=ms.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
//removing elements from multiset
cout<<"enter the element you want to erase:"<<endl;
int erase_num;
cin>>erase_num;
int op=ms.erase(erase_num);
cout<<"The multiset after removal of specified element becomes:"<<endl;
multiset<int,less<int>>::iterator it2;
for(it2=ms.begin();it2!=ms.end();it2++)
{
cout<<*it2<<" ";
}
cout<<endl;
//lower bound,upper bound for multisets
int lower_bound_element,upper_bound_element;
cout<<"Enter the element for which you want to calculate the lower_bound:";
cin>>lower_bound_element;
cout<<*ms.lower_bound(lower_bound_element)<<endl;
cout<<"Enter the element for which you want to calculate the upper_bound:";
cin>>upper_bound_element;
cout<<*ms.upper_bound(upper_bound_element)<<endl;
//searching for elements using find and then erasing it
int find_element;
multiset<int,less<int>>::iterator it3;
cout<<"enter the element you want to find:"<<endl;
cin>>find_element;
it3=ms.find(find_element);
ms.erase(it3);
multiset<int,less<int>>::iterator it4;
cout<<"Multiset after the searched element is erased:"<<endl;
for(it4=ms.begin();it4!=ms.end();it4++)
{
cout<<*it4<<" ";
}
return 0;
}