-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpair.cpp
46 lines (32 loc) · 778 Bytes
/
pair.cpp
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
#include <iostream>
#include <list>
#include <unordered_map>
using namespace std;
using node_t = std::pair<int, int>;
void print_list(std::list<node_t>& list_) {
for (auto it : list_)
cout << it.first << ":" << it.second << std::endl;
}
int main() {
std::unordered_map<int, std::list<node_t>::iterator> umap_;
std::list<node_t> list_;
std::pair<int, int> pr = {10, 100};
list_.push_back(pr);
umap_[10] = list_.begin();
pr.first = 20;
pr.second = 200;
list_.push_front(pr);
umap_[20] = list_.begin();
print_list(list_);
int key = 20;
auto it = umap_[key];
auto& node = *it;
node.first = 30;
node.second = 300;
cout << "============" << std::endl;
print_list(list_);
//dont use reference
//list_.erase(node);
print_list(list_);
return 0;
}