File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
// Lets make a function to print map and getting its size
5+
6+
void print(unordered_map<int,string> &m)
7+
{
8+
cout<<"Size of the map is "<<m.size()<<endl;
9+
for (auto pr :m)
10+
cout<<pr.first<<" "<<pr.second<<" "<<endl;
11+
}
12+
13+
int main ()
14+
{
15+
// 1. inbuilt impletation : It uses hash table it dont uses trees like map // here keys will make hash value
16+
// 2. Time complexity : O(1)-> Insertion and access
17+
// 3. valid keys datatypes : we cant keep all type of data types like pair of pair
18+
// we can use int double string float ... cz these all have possible hash value
19+
unordered_map<int,string>m;
20+
// unordered map does not store in sorted manner it will print randomly
21+
22+
m[8]="Shivendra"; // insertion takes O(1)
23+
m[3]="abc";
24+
m[5]="cdc";
25+
m.insert({1,"shiv"});
26+
/*map<int,string>:: iterator it;
27+
for (it=m.begin();it!=m.end();++it)
28+
{
29+
cout<<it->first<<" "<<it->second<<" "<<endl; // it will give the sorted output
30+
}*/
31+
/*m.find // O(1)
32+
m.earese// o(1)*/
33+
for (auto &pr :m){
34+
cout<<pr.first<<" "<<pr.second<<" "<<endl;
35+
// this will also work as same like above commented code
36+
37+
}
38+
}

0 commit comments

Comments
 (0)