-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathset.cpp
More file actions
58 lines (40 loc) · 1.33 KB
/
set.cpp
File metadata and controls
58 lines (40 loc) · 1.33 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
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;
int main() {
set<int> st1; // Sorts the elements in ascending order
st1.insert(40);
st1.insert(30);
st1.insert(60);
st1.insert(20);
st1.insert(50);
cout << "\nSt1: ";
for (auto i : st1) cout << i << " ";
set<int, greater<int>> st2(st1.begin(), st1.end()); // Sorts the elements in descending order
cout << "\nSt2: ";
for (auto i : st2) cout << i << " ";
unordered_set<int> st3; // Doesn't sort the elements
st3.insert(40);
st3.insert(30);
st3.insert(60);
st3.insert(20);
st3.insert(50);
cout << "\nSt3: ";
for (auto i : st3) cout << i << " ";
cout << "\nlower bound of 40 in st1 is: " << *st1.lower_bound(40);
cout << "\nlower bound of 41 in st1 is: " << *st1.lower_bound(41);
cout << "\nupper bound of 40 in st1 is: " << *st1.upper_bound(40);
cout << "\nupper bound of 41 in st1 is: " << *st1.upper_bound(41);
st1.clear();
cout << "\nIs st1 empty: " << st1.empty();
cout << "\nSize of st2: " << st2.size();
st2.erase(30);
st2.erase(60);
cout << "\nSt2: ";
for (auto i : st2) cout << i << " ";
cout << "\n";
if (st2.find(40) != st2.end()) cout << "40 is found in set 2";
else cout << "40 is not found in set 2";
return 0;
}