-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.cpp
More file actions
37 lines (31 loc) · 838 Bytes
/
set.cpp
File metadata and controls
37 lines (31 loc) · 838 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
#include<bits/stdc++.h>
#include <set>
#include <iostream>
using namespace std;
int main() {
set < int > s;
for (int i = 1; i <= 10; i++) {
s.insert(i);
}
cout << "Elements present in the set: ";
for (auto it = s.begin(); it != s.end(); it++) {
cout << * it << " ";
}
cout << endl;
int n = 2;
if (s.find(2) != s.end())
cout << n << " is present in set" << endl;
s.erase(s.begin());
cout << "Elements after deleting the first element: ";
for (auto it = s.begin(); it != s.end(); it++) {
cout << * it << " ";
}
cout << endl;
cout << "The size of the set is: " << s.size() << endl;
if (s.empty() == false)
cout << "The set is not empty " << endl;
else
cout << "The set is empty" << endl;
s.clear();
cout << "Size of the set after clearing all the elements: " << s.size();
}