forked from shubham7668/hacktober
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10. Unordered_map.cpp
76 lines (53 loc) · 1.12 KB
/
10. Unordered_map.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
**** Unordered_map: ****
Used to store key-value pairs
Uses Hashing Algorithms
It has no specific order of keys.
#include<iostream>
#include<unordered_map> m;
using namespace std;
int main()
{
unordered_map<string ,int> m;
m["gfg"]= 20;
m["ide"]=30;
m.insert(["courses", 15]);
for(auto x: m)
cout<<x.first<<" "<<x.second<<endl;
return 0;
}
// Program 2
#include<iostream>
#include<unordered_map> m;
using namespace std;
int main()
{
unordered_map<string, int> m;
m["gfg"]= 20;
m["ide"]= 30;
m["courses"]= 15;
if(m.find("ide")!=m.end())
cout<<"Found\n";
else
cout<<"Not Found\n";
for(auto it = m.begin(); it!=m.end(); it++)
cout<<(it->first)<<" "<<(it->second)<<endl;
if(m.count("ide") > 0)
cout<<"Found";
else
cout<<"Not Found";
}
#include<iostream>
#include<unordered_map>m;
using namespace std;
int main()
{
unordered_map<string , int> m;
m["gfg"]=20;
m["ide"]=30;
m["courses"]=15;
cout<<m.size()<<" ";
m.erase("ide");
m.erase(m.begin());
cout<<m.size()<<" ";
return 0;
}