-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuild_hashmap.cpp
More file actions
50 lines (41 loc) · 849 Bytes
/
Build_hashmap.cpp
File metadata and controls
50 lines (41 loc) · 849 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<unordered_map>
#include<map>
using namespace std;
int main()
{
unordered_map<string,int> h;
///insert
h["Mango"]=200;
///second insert
h.insert(make_pair("Apple",120));
///search
if(h.count("Apple")==1)
{
cout<<"Price of Apple "<<h["Apple"];
}
cout<<endl;
h["Chiku"]=h["Apple"]+20;
///delete
h.erase("Chiku");
if(h.count("Chiku")==0)
{
cout<<"Chiku doesn't exist";
}
else
{
cout<<"price of chiku is "<<h["Chiku"];
}
cout<<endl;
///Iterators to search
auto f=h.find("Apple");
if(f!=h.end())
{
cout<<"Price of Apple "<<f->second<<endl;
}
for(auto it:h)
{
cout<<it.first<<"->"<<it.second;
cout<<"\n";
}
}