Skip to content

STL Map Operations Added #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions CPP/stl/Maps Operations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
//key,value pairs like dictionary in python
map<int,int>mp;
mp.insert(pair<int,int>(2,20));
mp.insert(pair<int,int>(3,10));

//mp[key]=value
mp[4]=80;

cout<<mp.size()<<endl;

for (auto it=mp.begin();it!=mp.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}

//print value of any particular key in key value pair
cout<<mp[3]<<endl;

//to delete one key value pair enter the key name of the pair
mp.erase(2);
cout<<mp.size()<<endl;

mp.clear();
if(mp.empty())
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}

return 0;
}