forked from AayushGupta988/CPPstls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.cpp
44 lines (35 loc) · 864 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
#include <iostream>
#include <set>
using namespace std;
void find(set<int> s, int n)
{
if (s.find(n) != s.end())
cout << "Found" << endl;
else
cout << "Not found" << endl;
}
int main()
{
set<int> s;
s.insert(1);
s.insert(3);
s.insert(5);
s.insert(7);
s.insert(9);
s.insert(9);
int n;
cout << "Number: ";
cin >> n;
find(s, n);
for (set<int>::iterator i = s.begin(); i != s.end(); i++)
cout << *i << endl;
for (set<int>::reverse_iterator r = s.rbegin(); r != s.rend(); r++)
cout << *r << endl;
s.erase(9);
find(s, 9);
// returns iterator to next greater value
cout << *s.upper_bound(3) << endl;
// returns iterator having value not less than 1
cout << *s.lower_bound(1) << endl;
return 0;
}