-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.cpp
More file actions
46 lines (36 loc) · 816 Bytes
/
Copy pathset.cpp
File metadata and controls
46 lines (36 loc) · 816 Bytes
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
#include <iostream>
#include <set> // uses Binary Search Tree (BST)
using namespace std;
int main()
{
set<int> s; // duplicate elements not allowed
s.insert(5);
s.insert(5);
s.insert(5);
s.insert(1);
s.insert(6);
s.insert(6);
s.insert(0);
for (auto i : s)
{
cout << i << endl;
}
cout << endl;
set<int>::iterator itr = s.begin();
itr++; // moving the iterator to second element of the set
s.erase(itr);
for (auto i : s)
{
cout << i << endl;
}
cout << endl;
cout << "5 is present or not -> " << s.count(5) << endl;
cout << "-5 is present or not -> " << s.count(-5) << endl;
set<int>::iterator itr1 = s.find(5);
cout << "Value present at itr -> " << *itr1 << endl;
for (auto it = itr1; it != s.end(); it++)
{
cout << *it << endl;
}
return 0;
}