当前位置: 首页 > wzjs >正文

网站建设广州合理使用说明

网站建设广州,合理使用说明,wordpress 编辑器模板,新乐市建设银行网站unordered_set类 unordered_set类的介绍 1. 在使用unordered_set类时&#xff0c;必须包含 #include <unordered_set> 这一行。 2. unordered_set类的底层其实是一个哈希桶结构&#xff0c;使用时需要显示实例化。 3. 下面是unordered_set类的官方文本介绍&#xff0c;里…

unordered_set类

unordered_set类的介绍

1. 在使用unordered_set类时,必须包含 #include <unordered_set> 这一行。

2. unordered_set类的底层其实是一个哈希桶,使用时需要显示实例化

3. 下面是unordered_set类的官方文本介绍,里面有详细的用法讲解。

- C++ Reference https://legacy.cplusplus.com/reference/unordered_set/

unordered_set类对象的常见构造 

1. unordered_set<int> us1,什么也不需要传入,构造一个空的unordered_set类对象

2. unordered_set<int> us2(s1.begin(),s1.end()),使用另一个unordered_set类对象进行迭代器构造

3. unordered_set<int> us3(const unordered_set<int>& us2),使用另一个unordered_set类对象进行拷贝构造

#include <iostream>
#include <unordered_set>
using namespace std;int main()
{unordered_set<int> us1;unordered_set<int> us2(us1.begin(), us1.end());unordered_set<int> us3(us2);return 0;
}

unordered_set类对象的容量操作  

1. unordered_set.size(),返回unordered_set类对象有效元素个数

2. unordered_set.empty(),检测unordered_set类对象有效节点是否为空为空返回true不为空返回flase

#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{unordered_set<int> us1;us1.insert(1);us1.insert(3);us1.insert(2);us1.insert(4);us1.insert(6);us1.insert(5);cout << us1.size() << endl;//6cout << us1.empty() << endl;//0return 0;
}

unordered_set容器的修改操作 

1. unordered_set.insert(int num)向unordered_set类对象中插入整数num如果插入unordered_set类对象已有的元素则插入失败

2. unordered_set.erase(int num)向unordered_set类对象中删除整数num如果删除unordered_set类对象没有的元素则删除失败

3. unordered_set.erase(iterator pos)向unordered_set类对象中删除迭代器为pos的值

4. unordered_set.find(int num)检查unordered_set类对象中是否存在某个特定的元素num效率为log(N)如果找到了则返回指向元素num的迭代器如果没有找到则返回指向end()的迭代器

5. unordered_set.count(int num)检查unordered_set类对象中是否存在某个特定的元素num返回元素num的个数

#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{unordered_set<int> us1;us1.insert(1);us1.insert(3);us1.insert(2);us1.insert(4);us1.insert(6);us1.insert(5);us1.insert(5);us1.insert(5);for (auto e : us1){cout << e << " ";//1 3 2 4 6 5 }cout << endl;us1.erase(us1.begin());us1.erase(5);for (auto e : us1){cout << e << " ";//3 2 4 6}cout << endl;auto a = us1.find(4);if (a != us1.end()){cout << *a << endl;//4}return 0;
}

unordered_map类 

unordered_map类的介绍

1. 在使用unordered_map类时,必须包含 #include <unordered_map> 这一行。

2. unordered_map类的底层其实是一个哈希桶,使用时需要显示实例化

3. 下面是unordered_map类的官方文本介绍,里面有详细的用法讲解。

- C++ Reference https://legacy.cplusplus.com/reference/unordered_map/

unordered_map类对象的常见构造 

1. unordered_map<string,string> s1,什么也不需要传入,构造一个空的unordered_map类对象

2. unordered_map<string,string> s2(s1.begin(),s1.end()),使用另一个unordered_map类对象进行迭代器构造

3. unordered_map<string,string> s3(const unordered_mapmap<string,string>& s2),使用另一个unordered_map类对象进行拷贝构造

#include <iostream>
#include <unordered_map>
using namespace std;int main()
{unordered_map<string, int> s1;unordered_map<string, int> s2(s1.begin(), s1.end());unordered_map<string, int> s3(s2);return 0;
}

1. map类对象的初始化分为两种。 

2. 如果使用号,则为拷贝初始化;如果不使用号,则为直接初始化。 

#include <iostream>
#include <unordered_map>
using namespace std;int main()
{unordered_map<string, int> s1 = { {"苹果",1} ,{"梨子",1} };unordered_map<string, int> s2{ {"苹果",1} ,{"梨子",1} };return 0;
}

unordered_map类对象的修改操作 

1. unordered_map.insert({key,value})向unordered_map类对象中插入键值对如果插入unordered_map类对象已有的键则插入失败

2. unordered_map.find(key)检查unordered_map类对象中是否存在某个特定的键key效率为log(N)返回一个迭代器如果找到了则返回指向键key的迭代器如果没有找到则返回指向end()的迭代器

3. unordered_map.count(key)检查map类对象中是否存在某个特定的键key返回键key的个数

4. unordered_map.erase(key)向map类对象中删除键为key的键值对如果删除map类对象没有键key则删除失败

http://www.dtcms.com/wzjs/107964.html

相关文章:

  • 南京网站建设包括哪些广东做seo的公司
  • 比较好的网站建设百度一下百度搜索官网
  • 长春网站建设哪家靠谱百度博客收录提交入口
  • 重庆做网站怎么做seo快速排名工具
  • 网站建设需要云主机吗青岛百度关键词优化
  • 网站开发技术孵化行者seo无敌
  • 做算法的网站长尾关键词挖掘爱站网
  • 在线做效果图有哪些网站网站优化排名工具
  • 大型网站建设推广短视频seo关键词
  • 网站怎么做查询功能搜索引擎优化的主要内容
  • 房地产营销门户网站建设深圳外贸推广公司
  • 网站设计建设 武汉seo文章关键词怎么优化
  • 招聘网站建设人员条件seo实战密码电子书
  • 网站建设开票属于哪个名称福州网络推广运营
  • 政府网站的建设背景阳江seo
  • 网站开发总结 优帮云百度网盘破解版
  • dede网站百度统计怎么做小米市场营销案例分析
  • wordpress mepal做网站关键词优化的公司
  • 国外做枪视频网站百度关键词挖掘查排名工具
  • 长沙私人做网站丹东网站seo
  • logo在线设计网站百度学术论文查重入口
  • 网站专题报道怎么做百度推广开户渠道
  • 怎么做网站省钱哪个浏览器看黄页最快夸克浏览器
  • html5做的网站有哪些百度推广平台登陆
  • 网站数据抓取怎么做windows优化大师可靠吗
  • 养生网站源码下载百度服务
  • 怎么把网站做二维码网站如何赚钱
  • 智慧团建官网登录口手机版北京网站优化推广公司
  • 日本做的视频网站nba交易最新消息汇总
  • 做淘宝客网站详细步骤优化大师电脑版官方