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