-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathset.cpp
More file actions
35 lines (29 loc) · 772 Bytes
/
set.cpp
File metadata and controls
35 lines (29 loc) · 772 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
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> mySet;
// Inserting elements
mySet.insert(10);
mySet.insert(20);
mySet.insert(15);
mySet.insert(10); // Duplicate
// Displaying elements
cout << "Set elements: ";
for (auto it = mySet.begin(); it != mySet.end(); ++it)
cout << *it << " ";
cout << endl;
// Finding an element
int key = 15;
if (mySet.find(key) != mySet.end())
cout << key << " is found in the set\n";
else
cout << key << " is not found\n";
// Removing an element
mySet.erase(10);
cout << "After removing 10: ";
for (auto it = mySet.begin(); it != mySet.end(); ++it)
cout << *it << " ";
cout << endl;
return 0;
}