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
#include <iostream>
#include <unordered_set>
int main() {
std::unordered_set<int> mySet = {1, 2, 3, 4, 5};
// Insertion
mySet.insert(6);
mySet.insert(3); // Duplicate element, will not be inserted
// Lookup
if (mySet.find(3) != mySet.end()) {
std::cout << "3 is in the set." << std::endl;
}
// Deletion
mySet.erase(2);
// Iterating over the set
std::cout << "Elements in mySet: ";
for (int elem : mySet) {
std::cout << elem << " ";
}
std::cout << std::endl;
return 0;
}
Back to std_unordered_set