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 303794d

Browse files
authored
Create 03 Maps creation.cpp
1 parent 90b2bff commit 303794d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
int main ()
4+
{
5+
map<int,string>m;
6+
// all the keys of map will always be unique
7+
// map stores keys & values in sorted order
8+
// if we keep string then it will be stored in lexographical order
9+
10+
m[8]="Shivendra"; // insertion takes O(logn)
11+
m[3]="abc"; // O(logm)
12+
m[5]="cdc"; // when we wrote this even after there is no value it will take any value by it self
13+
m.insert({1,"shiv"});
14+
/*map<int,string>:: iterator it;
15+
for (it=m.begin();it!=m.end();++it)
16+
{
17+
cout<<it->first<<" "<<it->second<<" "<<endl; // it will give the sorted output
18+
}*/
19+
for (auto &pr :m){
20+
cout<<pr.first<<" "<<pr.second<<" "<<endl;
21+
// this will also work as same like above commented code
22+
23+
}
24+
}

0 commit comments

Comments
(0)

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