-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnordered_Map.cpp
More file actions
44 lines (44 loc) · 1.04 KB
/
Unordered_Map.cpp
File metadata and controls
44 lines (44 loc) · 1.04 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
// key,value pair
// keys are always unique and but the map is unordered
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map<int, int> mp;
mp[0] = 1;
mp[3] = 1;
mp[2] = 5;
mp[1] = 6;
mp[5] = 19;
mp.insert(pair<int, int>(6, 40)); // sorted accorind to the key
mp[1] = 100; // overwrite
for (auto it : mp)
{
cout << it.first << " " << it.second << "\n";
}
cout << mp.size() << "\n";
cout << mp.empty() << "\n";
cout << mp[2] << "\n";
cout << mp[12] << "\n";
//
unordered_map<string, int> m;
m["abc"] = 20;
m["def"] = 30;
m["ghi"] = 40;
if (m.find("abc") != m.end())
cout << "Found"
<< "\n"
<< m.find("abc")->second << "\n";
else
{
cout << "Not Fount"
<< "\n";
}
for (auto it = m.begin(); it != m.end(); it++)
{
cout << it->first << " " << it->second << "\n";
}
cout << m.size() << "\n";
cout << m.erase("abc");
}