1. Map Declaration.
2. insert()
3. at(), operator ‘{)”
4. size()
5. begin(), end()
6. max_size()
7. empty()
8. erase()
9. clear()
10. count(),
11. find()
12. upper_bound()
13. lower_bound()
14.operator(=)
Example:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<int,int> mp ; /// int 1--->index or key and int2 ---> value
/// mp et<int,greater<int>> mp ; /// demp cending array
mp.insert({1,1});
mp.insert({2,2});
mp.insert({3,3});
mp.insert({4,4});
mp.insert({5,5});
mp.insert({4,6});
mp.insert({5,7});
map<int,string> mp2;
mp2.insert({1,"hasab"});
mp2.insert({2,"karim"});
mp2.insert({3,"jabed"});
mp2.insert({4,"rakib"});
map<int, int> mp3;
mp3[1] = 10;
mp3[2] = 300;
mp3[3] = 20;
map<int, string> mp4;
mp4[1] = 10;
mp4[2] = 300;
mp4[3] = 20;
cout << "map-begin : " << mp.begin() << endl;
cout << "map-end : " << mp.end() << endl;
cout << "size : " << mp.size() << endl;
cout << "max-size : " << mp.max_size() << endl;
cout << "empty : " << mp.empty() << endl;
for (auto it : mp2 )
{
cout << it.first << " " << it.second <<endl;
}
// erase
mp et<int>::iterator it; /// iterator
it = mp .begin();
advance(it, 3); /// inmp ert index
mp .eramp e(it); /// delete hobe
// find
map<int>::iterator it; /// iterator
it = mp .find(3);
if (it != mp .end())
cout << "Find" << endl;
else
cout << "Not Find" << endl;
/// count
int c = s.count(3);
if (c = 1)
{
cout << "yes" << endl;
}
else
{
cout << "No" << endl;
}
for (auto it : s)
{
cout << it << " ";
}
// lower bound
map<int,int>::iterator it; /// iterator
it = mp.lower_bound(2);
if (it == mp.end())
cout << "the element imp larger to the grater element" << endl;
else
cout << "the lower bound :" << *it << endl;
// Upper bound
map<int>::iterator it; /// iterator
it = mp .upper_bound(2);
if (it == mp .end())
cout << "the element imp larger to the grater element" << endl;
else
cout << "the upper bound :" << *it << endl;
// print array
for (auto it : mp )
{
cout << it << " ";
}
/// normal iteration ///
mp et<int>::iterator it; /// iterator
for (it = mp .begin(); it != mp .end(); it++)
{
cout << *it << " ";
}
/// Insert ///
mp .insert(mp .begin(),99);/// input number
it = mp .begin();
advance(it, 3); /// insert index
mp .insert(it, 2,9); /// input number and koi bar print hobe
/// Erase ///
mp .erase(mp 3.begin());/// erase by index number
it = mp 3.begin();
advance(it, 3); /// insert index
mp 3.insert(it, 2,9); /// input number and koi bar print hobe
mp 3.remove(22);
mp 4.sort();
mp 3.unique();
swap(mp 2, mp 3);
mp .merge(mp 3);
swap(mp , mp 2); /// swap between 2 array ;
sort(mp .begin(),mp .end());
sort(mp .begin()+4,mp .end());
reserse(mp .begin(),mp .end());
reserse(mp .begin()+4,mp .end());
for (int i = 0; i < mp .mp ize(); i++)
{
cout << mp [i] << " ";
}
vector<int>::iterator it;
it = mp .begin() + 5;
}
0 Comments