#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// 双向链表
struct ListNode {
int times;
unordered_set<string> bucket;
ListNode *prev;
ListNode *next;
ListNode() {
prev = nullptr;
next = nullptr;
}
ListNode(int times, string key) : ListNode() {
this->times = times;
bucket.emplace(key);
}
};
int main() {
unordered_map<string, ListNode *> map;
ListNode *node = new ListNode();
map.emplace("haha", node);
// map["haha"] = node;
ListNode *node2 = new ListNode(1, "x");
map.emplace("haha", node2);
// map["haha"] = node2;
}
在此输入图片描述
- 为什么关键字haha对应的值没有变化?
它应该是 0xec1e20 而不是 0xec1c90。
- 当我使用操作符[]时,我可以成功更改对应的值哈哈