-
Notifications
You must be signed in to change notification settings - Fork 492
/
set.cpp
57 lines (49 loc) Β· 965 Bytes
/
set.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
// /* Set in C++ -->
#include<bits/stdc++.h>
using namespace std;
int main(){
set<int>s;
cout<<"enter set size->";
int n;
cin>>n;
for(int i=0;i<n;i++){
int val;
cout<<"enter Value->";
cin>>val;
s.insert(val);
}
cout<<endl;
cout<<"Size of Set ->"<<s.size()<<endl;
cout<<"display Set elements->"<<endl;
for(auto it=s.begin(); it!=s.end(); it++){
cout<<*it<<" ";
}
cout<<endl;
cout<<"Searching in Set->"<<endl;
cout<<"Find the element You are in Search for->";
int key;
cin>>key;
if(s.find(key)!=s.end())
{
cout<<key<<" is present";
}
else
{
cout<<key<<" is not present";
}
cout<<endl;
}
/* OUTPUT:
enter set size->5
enter Value->1
enter Value->2
enter Value->3
enter Value->4
enter Value->5
Size of Set ->5
display Set elements->
1 2 3 4 5
Searching in Set->
Find the element You are in Search for->4
4 is present
*/