14.hash_set(已过时,被unorded_set替代)
2024-08-30 22:19:41
#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();
}
最新文章
- [LeetCode] Increasing Triplet Subsequence 递增的三元子序列
- 16 On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima 1609.04836v1
- bash fifo管道使用测试例子
- java生成excel文件
- Java微博搜索关键字采集
- 营业额统计(bzoj1588)
- git push throws error: RPC failed; result=22, HTTP code = 411的解决办法
- JDK版本不兼容问题之:一台机器安装多个版本的JDK
- Trie,HDU1875world puzzle
- Python中小中花括号的区别
- VBS 文件选择框,选择Excel文件
- node.js express mvc轻量级框架实践
- ●UVA 1608 Non-boring sequences
- 【BZOJ3110】【ZJOI2013】k大数查询
- 一、Ansible安装
- Spring学习四
- 20170711xlVBA自定义分类汇总一例
- .NET/C# 判断某个类是否是泛型类型或泛型接口的子类型
- swift3.0 保存图片到本地,申请权限
- python获取输入参数