-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstl_hashmap.cpp
More file actions
41 lines (33 loc) · 987 Bytes
/
stl_hashmap.cpp
File metadata and controls
41 lines (33 loc) · 987 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
#include<iostream>
#include<unordered_map>
using namespace std;
int main()
{
//unordered_map<typeof_key,typeof_value> name;
unordered_map<string,int> h;
//in hashmap we insert key-value pair
pair<string,int> p("Mango",100);
//p.first="Pineapple";
//cout<<p.first<<endl; //this will print the key
//cout<<p.second<<endl; //this will print the value
h.insert(p); //create a pair then insert in hashmap
h.insert(make_pair("Pineapple",50));
h.insert(make_pair("Apple",150));
h.insert(make_pair("Gauva",60));
for(auto iterator:h)
{
cout<<iterator.first<<"->"<<iterator.second<<endl;
}
cout<<endl;
//Bucket iterate
for(int i=0;i<h.bucket_count();i++)
{
cout<<i<<"->";
//Iterate on every linked list
for(auto it=h.begin(i);it!=h.end(i);it++)
{
cout<<"("<<it->first<<","<<it->second;
}
cout<<endl;
}
}