-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.cpp
97 lines (76 loc) · 1.68 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>
#include<conio.h>
#include<set>
using namespace std;
int main()
{
set<int,greater<int> >s;
set<int> s2,s3,s4;
s.insert(1);
s.insert(3);
s.insert(2);
s.insert(2);
s.insert(5);
s.insert(4);
s.emplace(7);
s.emplace(8);
s2.insert(1);
s2.insert(2);
s2.insert(3);
s2.insert(4);
s3.insert(1);
s3.insert(2);
s3.insert(4);
s3.insert(4);
cout<< s.size() <<endl;
cout<< s.max_size() <<endl;
set<int> :: iterator it;
for(it= s.begin(); it!=s.end(); it++)
{
cout<< *it <<" ";
}
cout<<endl;
it= s.find(2);
if(it!=s.end())cout<< "Find"<<endl;
else cout<< "Not Find"<<endl;
set<int> :: iterator it1;
it1= s.begin();
advance(it1,3);
s.erase(it1);
for(auto it1 : s)cout<< it1 <<" ";
cout<<endl;
//s.clear();
if(s.empty())cout<< "Empty" <<endl;
else cout<< "Not Empty "<<endl;
int cnt= s.count(2);
cout<<cnt<<endl;
for(auto it : s)cout<< it << " ";
cout<< endl;
set<int> :: iterator it2;
it2 = s2.lower_bound(2);
if(it2==s2.end())
{
cout<< "The element is larger or equal to the Greater Element"<<endl;
}
else
{
cout<< "The lower bound of 2 is : "<< *it2 <<endl;
}
for(auto it3 : s3)cout<< it3 << " ";
cout<< endl;
set<int> :: iterator it3;
it3 = s3.upper_bound(3);
if(it3==s3.end())
{
cout<< "The element is larger or equal to the Greater Element"<<endl;
}
else
{
cout<< "The upper bound of 3 is : "<< *it3 <<endl;
}
s2.swap(s3);
for(auto it2 : s2)cout<< it2 << " ";
cout<<endl;
s2= s4;
getch();
}