2021-4-1 C++ STL之unordered_map
时间:2021-04-02 13:12:10
收藏:0
阅读:0
unordered_map
unordered_map底层实现是哈希表,所以不会根据key来排序
undered_map<T1,T2> m; //T1是key值,T2是value值,初始的时候 m 是空映射
插入方式:键值对的形式插入
unordered_map<int, int> map;
for (int i=0; i<list.size(); i++){
map[i] = list[i];
}
cout << map[0] << endl;
for (unordered_map<int, int>::iterator i = map.begin(); i != map.end(); i++){
cout << i->first << ‘ ‘ << i->second << endl;
}
if (map.find(3) != map.end()) {
cout << "find key=" << map.find(3)->first << ", value=" << map.find(3)->second << endl;
}
if (map.count(5) > 0) {
cout << "find 5: " << map.count(5) << endl;
}
评论(0)