-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmap
More file actions
48 lines (37 loc) · 1.25 KB
/
map
File metadata and controls
48 lines (37 loc) · 1.25 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
/* *********************************************************
* KNOWLEDGE CENTER
* std::map
* Detailed Video Explanation: https://youtu.be/w1vDg3iBbLA
********************************************************** */
#include <iostream>
#include <map>
using namespace std;
int main() {
map<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"});
for(auto& p: m)
cout << "{" << p.first << ", " << p.second << "} ";
cout << endl;
//auto it = m.erase(m.find(10));
//cout << it->first << endl;
int num_erased = m.erase(15);
cout << "num_erased = " << num_erased << endl;
auto ub = m.upper_bound(15);
auto lb = m.lower_bound(15);
cout << "ub = " << ub->first << endl;
cout << "lb = " << lb->first << endl;
m.insert({{-10, "apple"}, {-30, "orange"}, {-20, "mango"}});
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;
}