18.查询效率最高的unordered_map

 1 #include <string>
 2 #include <iostream>
 3 //查询性能最高
 4 //增删查改与map是一样的,但是本质区别就是unordered_map底层是hash表,map底层是红黑树
 5 #include <unordered_map>
 6 using namespace std;
 7 
 8 
 9 void main()
10 {
11     unordered_map<string, double>mymap{ {"a1",113},{ "a2",143 },{ "a3",1123 } };
12 
13     //不允许重复
14     mymap.insert(pair<string, double>("a4", 345));
15 
16     mymap.insert(unordered_map<string, double>::value_type("a5", 3425));
17 
18     for (auto i : mymap)
19     {
20         cout << i.first << "  " << i.second << endl;
21     }
22 
23     auto it = mymap.find("a1");
24     if (it != mymap.end())
25     {
26         cout << it->second << endl;
27     }
28     cin.get();
29 }

 

posted @ 2018-03-23 12:27  喵小喵~  阅读(853)  评论(0编辑  收藏  举报