MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CPP/stl/Maps Operations.cpp:5–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using namespace std;
4
5int 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}

Callers

nothing calls this directly

Calls 3

insertMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected