Skip to content

Commit 5eb2608

Browse files
Merge pull request #36 from BhaswatiR/main
STL Map Operations Added
2 parents 4b21c7c + 4ccf8df commit 5eb2608

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

CPP/stl/Maps Operations.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<iostream>
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
//key,value pairs like dictionary in python
8+
map<int,int>mp;
9+
mp.insert(pair<int,int>(2,20));
10+
mp.insert(pair<int,int>(3,10));
11+
12+
//mp[key]=value
13+
mp[4]=80;
14+
15+
cout<<mp.size()<<endl;
16+
17+
for (auto it=mp.begin();it!=mp.end();it++)
18+
{
19+
cout<<it->first<<" "<<it->second<<endl;
20+
}
21+
22+
//print value of any particular key in key value pair
23+
cout<<mp[3]<<endl;
24+
25+
//to delete one key value pair enter the key name of the pair
26+
mp.erase(2);
27+
cout<<mp.size()<<endl;
28+
29+
mp.clear();
30+
if(mp.empty())
31+
{
32+
cout<<"Yes"<<endl;
33+
}
34+
else
35+
{
36+
cout<<"No"<<endl;
37+
}
38+
39+
return 0;
40+
}

0 commit comments

Comments
 (0)