Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d6f37a0

Browse files
authored
Create 04 print map & its size.cpp
1 parent 303794d commit d6f37a0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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(map<int,string> &m)
7+
{
8+
cout<<"Size of the map is "<<m.size()<<endl;
9+
for (auto pr :m) // this loop is of O(nlogn)
10+
cout<<pr.first<<" "<<pr.second<<" "<<endl;
11+
}
12+
13+
int main ()
14+
{
15+
map<int,string>m;
16+
// all the keys of map will always be unique
17+
// map stores keys & values in sorted order
18+
// if we keep string then it will be stored in lexographical order
19+
20+
m[8]="Shivendra"; // insertion takes O(logn)
21+
m[3]="abc"; // O(logm)
22+
m[5]="cdc"; // when we wrote this even after there is no value it will take any value by it self
23+
m.insert({1,"shiv"});
24+
print(m);
25+
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /