#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#include <iostream>
#include <hash_set>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std; //hash_set常规用法
void main()
{
////哈希表不需要考虑碰撞,查询的效率高,不能有重复的数据
//hash_set<int> myset{ 1,1,1,4,2134,12,34,56,34 };
//myset.insert(26);
//for (auto i : myset)
//{
// cout << i << endl;
//}
////正向迭代
//for (auto ib = myset.begin(), ie = myset.end(); ib != ie; ib++)
//{
// cout << *ib << endl;
//} ////反向迭代
//for (auto rb = myset.rbegin(), re = myset.rend(); rb != re; rb++)
//{
// cout << *rb << endl;
//} ////存储的数据个数
//cout << myset.size() << endl;
////哈希表大小
//cout << myset.bucket_count() << endl; //哈希表不需要考虑碰撞,查询的效率高,不能有重复的数据
hash_set<string> myset{ "microsoft","apple","oracle","tecent" };
myset.insert("huawei");
for (auto i : myset)
{
cout << i << endl;
}
//正向迭代
/*for (auto ib = myset.begin(), ie = myset.end(); ib != ie; ib++)
{
cout << *ib << endl;
}*/ //反向迭代
/*for (auto rb = myset.rbegin(), re = myset.rend(); rb != re; rb++)
{
cout << *rb << endl;
}*/ //存储的数据个数
/*cout << myset.size() << endl;*/
//哈希表大小
/*cout << myset.bucket_count() << endl;*/ auto it = myset.find("apple"); if (it != myset.end())
{
cout << "find" << endl;
cout << *it << endl;
}
else
{
cout << "not find" << endl;
}
cin.get();
}
本文网址:https://www.zhankr.net/141685.html