-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSet_Stl.cpp
More file actions
65 lines (65 loc) · 1.68 KB
/
Set_Stl.cpp
File metadata and controls
65 lines (65 loc) · 1.68 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
62
63
64
65
#include <iostream>
#include <set>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
set<int> st;
set<int>::iterator it;
int choice, item;
while (1)
{
cout<<"\n---------------------"<<endl;
cout<<"Set Implementation in Stl"<<endl;
cout<<"\n---------------------"<<endl;
cout<<"1.Insert Element into the Set"<<endl;
cout<<"2.Delete Element of the Set"<<endl;
cout<<"3.Size of the Set"<<endl;
cout<<"4.Find Element in a Set"<<endl;
cout<<"5.Dislplay by Iterator"<<endl;
cout<<"6.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter value to be inserted: ";
cin>>item;
st.insert(item);
break;
case 2:
cout<<"Enter the element to be deleted: ";
cin>>item;
st.erase(item);
break;
case 3:
cout<<"Size of the Set: ";
cout<<st.size()<<endl;
break;
case 4:
cout<<"Enter the element to be found: ";
cin>>item;
it = st.find(item);
if (it != st.end())
cout<<"Element "<<*it<<" found in the set" <<endl;
else
cout<<"No Element Found"<<endl;
break;
case 5:
cout<<"Displaying Map by Iterator: ";
for (it = st.begin(); it != st.end(); it++)
{
cout << (*it)<<" ";
}
cout<<endl;
break;
case 6:
exit(1);
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}