-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMultiMap
More file actions
57 lines (44 loc) · 1.5 KB
/
MultiMap
File metadata and controls
57 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* *********************************************************
* KNOWLEDGE CENTER
* std::multimap
* Detailed Video Explanation: https://youtu.be/nbZpBlQ_Dn8
********************************************************** */
/******
* Copyright: Abhishek
*
* ****/
#include <iostream>
#include <map>
using namespace std;
int main() {
multimap<int, string> m = {{10, "cat"}, {20, "dog"}, {5, "bat"}};
cout << "size = " << m.size() << endl;
for(auto& p: m)
cout << "{" << p.first << ", " << p.second << "} ";
cout << endl;
m.insert({100, "rabbit"});
m.insert({10, "fish"});
m.insert({{10, "cat"}, {12, "bat"}});
m.insert(make_pair<int, string>(12, "bat_2"));
for(auto& p: m)
cout << "{" << p.first << ", " << p.second << "} ";
cout << endl;
map<int, string> m2 = {{10, "aa"}, {20, "bb"}, {15, "cc"}, {5, "dd"}};
m.insert(m2.begin(), m2.end());
for(auto& p: m)
cout << "{" << p.first << ", " << p.second << "} ";
cout << endl;
//cout << "size = " << m.size() << endl;
//auto it = m.erase(10);//
//m.erase(m.find(10));
//cout << it->first << endl;
//cout << "size = " << m.size() << endl;
auto ub = m.upper_bound(15);
auto lb = m.lower_bound(15);
cout << "ub = " << ub->first << endl;
cout << "lb = " << lb->first << endl;
auto range = m.equal_range(10);
for(auto it = range.first; it != range.second; ++it)
cout << it->second << " ";
cout << endl;
}