哈希map(unordered_map)
在 unordered_map 内部,==使用的 Hash Table 对数据进行组织==,通过把键值 key 映射到 hash 表中的一个位置进行访问,根据 hash 函数的特点, unordered_map 对于元素查找的时间复杂度可以达到 O(1) ,但是,它的元素排列是无序的。具体例子如下:
int main() {
using namespace std;
// 首先创建一个无序 map,它的 key 使用 int 类型,value 使用 string 类型
unordered_map<int, string> unorderedMap;
// 三种插入新元素的方法,“茴”字有三种写法~
unorderedMap.insert(make_pair(0, "Alice"));
unorderedMap[1] = "Bob";
unorderedMap.insert(unordered_map<int, string>::value_type(2, "Candy"));
// 对内部元素挨个输出
for (auto iter = unorde