-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMultiset_Stl.cpp
71 lines (71 loc) · 2 KB
/
Multiset_Stl.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
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <set>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
multiset<int> ms;
multiset<int>::iterator it, it1;
int choice, item;
while (1)
{
cout<<"\n---------------------"<<endl;
cout<<"Multiset Implementation in Stl"<<endl;
cout<<"\n---------------------"<<endl;
cout<<"1.Insert Element into the Multiset"<<endl;
cout<<"2.Delete Element from the Multiset"<<endl;
cout<<"3.Find Element in a Multiset"<<endl;
cout<<"4.Count Elements with a specific key"<<endl;
cout<<"5.Size of the Multiset"<<endl;
cout<<"6.Display Multiset"<<endl;
cout<<"7.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter value to be inserted: ";
cin>>item;
if (ms.empty())
it1 = ms.insert(item);
else
it1 = ms.insert(it1, item);
break;
case 2:
cout<<"Enter value to be deleted: ";
cin>>item;
ms.erase(item);
break;
case 3:
cout<<"Enter element to find ";
cin>>item;
it = ms.find(item);
if (it != ms.end())
cout<<"Element found"<<endl;
else
cout<<"Element not found"<<endl;
break;
case 4:
cout<<"Enter element to be counted: ";
cin>>item;
cout<<item<<" appears "<<ms.count(item)<<" times."<<endl;
break;
case 5:
cout<<"Size of the Multiset: "<<ms.size()<<endl;
break;
case 6:
cout<<"Elements of the Multiset: ";
for (it = ms.begin(); it != ms.end(); it++)
cout<<*it<<" ";
cout<<endl;
break;
case 7:
exit(1);
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}