14.hash_set(已过时,被unorded_set替代)

 1 #define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
 2 #include <iostream>
 3 #include <hash_set>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <string>
 7 using namespace std;
 8 
 9 //hash_set常规用法
10 void main()
11 {
12     ////哈希表不需要考虑碰撞,查询的效率高,不能有重复的数据
13     //hash_set<int> myset{ 1,1,1,4,2134,12,34,56,34 };
14     //myset.insert(26);
15     //for (auto i : myset)
16     //{
17     //    cout << i << endl;
18     //}
19     ////正向迭代
20     //for (auto ib = myset.begin(), ie = myset.end(); ib != ie; ib++)
21     //{
22     //    cout << *ib << endl;
23     //}
24 
25     ////反向迭代
26     //for (auto rb = myset.rbegin(), re = myset.rend(); rb != re; rb++)
27     //{
28     //    cout << *rb << endl;
29     //}
30 
31     ////存储的数据个数
32     //cout << myset.size() << endl;
33     ////哈希表大小
34     //cout << myset.bucket_count() << endl;
35 
36     //哈希表不需要考虑碰撞,查询的效率高,不能有重复的数据
37     hash_set<string> myset{ "microsoft","apple","oracle","tecent" };
38     myset.insert("huawei");
39     for (auto i : myset)
40     {
41         cout << i << endl;
42     }
43     //正向迭代
44     /*for (auto ib = myset.begin(), ie = myset.end(); ib != ie; ib++)
45     {
46         cout << *ib << endl;
47     }*/
48 
49     //反向迭代
50     /*for (auto rb = myset.rbegin(), re = myset.rend(); rb != re; rb++)
51     {
52         cout << *rb << endl;
53     }*/
54 
55     //存储的数据个数
56     /*cout << myset.size() << endl;*/
57     //哈希表大小
58     /*cout << myset.bucket_count() << endl;*/
59 
60     auto it = myset.find("apple");
61 
62     if (it != myset.end())
63     {
64         cout << "find" << endl;
65         cout << *it << endl;
66     }
67     else
68     {
69         cout << "not find" << endl;
70     }
71     cin.get();
72 }

 

posted @ 2018-03-22 23:23  喵小喵~  阅读(252)  评论(0)    收藏  举报