-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path44.cpp
More file actions
64 lines (55 loc) · 1.4 KB
/
Copy path44.cpp
File metadata and controls
64 lines (55 loc) · 1.4 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
59
60
61
62
63
64
// #include<bits/stdc++.h>
#include <iostream>
#include <set>
int main()
{
// program to understand the set
std::set<int> s1;
// inserting into the set 1
s1.insert(40);
s1.insert(44);
s1.insert(0);
s1.insert(88);
s1.insert(3);
// printing the set elements
std::set<int>::iterator p;
for (p = s1.begin(); p != s1.end(); p++)
{
std::cout << *p << " ";
}
//all the elements are in ascending order
std::cout<<std::endl;
// inserting the existing elements again into the set
s1.insert(44);
s1.insert(88);
//shows that a set can have only unique elements
for (p = s1.begin(); p != s1.end(); p++)
{
std::cout << *p << " ";
}
std::cout<<std::endl;
//size of the set
std::cout<<"Size : "<<s1.size();
// creating another set
std::set<int> s2(s1.begin(),s1.end());
std::set<int>::iterator p2;
std::cout<<"Set 2 : ";
for (p2 = s2.begin(); p2 != s2.end(); p2++)
{
std::cout << *p2 << " ";
}
std::cout<<std::endl;
//now deleting the elements till 40
s2.erase(40);
std::cout<<"After Deletion....!"<<std::endl;
std::cout<<"Set 2 : ";
for (p2 = s2.begin(); p2 != s2.end(); p2++)
{
std::cout << *p2 << " ";
}
std::cout<<std::endl;
//erasing the whole set
s2.clear();
std::cout<<"Size of set 2 : "<<s2.size()<<std::endl;
return 0;
}