-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunordered_set.cpp
More file actions
35 lines (35 loc) · 785 Bytes
/
unordered_set.cpp
File metadata and controls
35 lines (35 loc) · 785 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 <bits/stdc++.h>
using namespace std;
// in unordred set the only difference is it is not in ordered form
int main()
{
unordered_set<int> s;
s.insert(10);
s.insert(5);
s.insert(15);
s.insert(20);
for (auto &it : s)
{
cout << it << " ";
}
cout << "\n";
for (auto it = s.begin(); it != s.end(); it++)
{
cout << (*it) << " ";
}
cout << s.size() << " ";
// clear the container
if (s.find(15) == s.end())
cout << "Not Found";
else
{
cout << "Found"
<< " " << *s.find(15);
}
cout << "\n";
// count return 1 if present no 0 no duplicate
// erase fn to remove a element or range of item
s.erase(15);
cout << s.size() << "\n";
}