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

网站模板素材电商运营转行后悔了

网站模板素材,电商运营转行后悔了,做公司网站图片算是商用吗,西安好的网站建设公司一、unordered_map unordered_map 是 C STL 中的一个关联容器,它有如下特点 unordered_map 存储键值对,使用哈希表实现 unordered_map 的每个键在容器中只能出现一次 unordered_map 的存储的键值对是无序的 平均情况下,查找、插入、删除都…

一、unordered_map

  • unordered_map 是 C++ STL 中的一个关联容器,它有如下特点
  1. unordered_map 存储键值对,使用哈希表实现

  2. unordered_map 的每个键在容器中只能出现一次

  3. unordered_map 的存储的键值对是无序的

  4. 平均情况下,查找、插入、删除都是 O(1) 时间复杂度


二、声明与初始化

#include <iostream>
#include <unordered_map>
#include <string>using namespace std;int main()
{// 空 unordered_mapunordered_map<string, int> map1;// 初始化 unordered_mapunordered_map<string, int> map2 = {{"Alice", 25},{"Bob", 30} };return 0;
}

三、插入元素

#include <iostream>
#include <unordered_map>
#include <string>using namespace std;int main()
{unordered_map<string, int> wordCount;// 使用 insert 方法wordCount.insert({ "apple", 3 });// 使用 operator[]wordCount["banana"] = 2;// 使用 emplace 方法wordCount.emplace("cherry", 5);return 0;
}

四、访问元素

1、演示
#include <iostream>
#include <unordered_map>
#include <string>using namespace std;int main()
{unordered_map<string, int> map = {{"Alice", 25},{"Bob", 30} };// 使用 operator[]cout << map["Alice"] << endl;cout << map["Bob"] << endl;// 使用 at 方法try {int result = map.at("Tom");}catch (out_of_range& e) {cout << "Key not found" << endl;}return 0;
}
# 输出结果25
30
Key not found
2、注意事项
  • 使用 operator[] 访问,如果元素不存在,会创建新元素
#include <iostream>
#include <unordered_map>
#include <string>using namespace std;int main()
{unordered_map<string, int> map = {{"Alice", 25},{"Bob", 30} };cout << "unordered_map 大小为:" << map.size() << endl;cout << map["Tom"] << endl;cout << "unordered_map 大小为:" << map.size() << endl;return 0;
}
# 输出结果unordered_map 大小为:2
0
unordered_map 大小为:3

五、遍历元素

#include <iostream>
#include <unordered_map>
#include <string>using namespace std;int main()
{unordered_map<string, int> map = {{"Alice", 25},{"Bob", 30} };// 使用迭代器for (auto it = map.begin(); it != map.end(); it++) {cout << it->first << ": " << it->second << endl;}cout << "----------" << endl;// 使用范围 for 循环for (auto& it : map) {cout << it.first << ": " << it.second << endl;}return 0;
}
# 输出结果Alice: 25
Bob: 30
----------
Alice: 25
Bob: 30

六、删除元素

#include <iostream>
#include <unordered_map>
#include <string>using namespace std;int main()
{unordered_map<string, int> map = {{"Alice", 25},{"Bob", 30},{"Tom", 35} };cout << "unordered_map 大小为:" << map.size() << endl;// 通过键删除map.erase("Bob");cout << "erase 操作之后,unordered_map 大小为:" << map.size() << endl;// 全部删除map.clear();cout << "clear 操作之后,unordered_map 大小为:" << map.size() << endl;return 0;
}
# 输出结果unordered_map 大小为:3
erase 操作之后,unordered_map 大小为:2
clear 操作之后,unordered_map 大小为:0

七、查找元素

#include <iostream>
#include <unordered_map>
#include <string>using namespace std;int main()
{unordered_map<string, int> map = {{"Alice", 25},{"Bob", 30} };auto it1 = map.find("Alice");if (it1 != map.end()){cout << it1->second << endl;}else {cout << "Key not found" << endl;}auto it2 = map.find("Tom");if (it2 != map.end()){cout << it2->second << endl;}else {cout << "Key not found" << endl;}return 0;
}
# 输出结果25
Key not found
http://www.dtcms.com/wzjs/466897.html

相关文章:

  • 网站建设中字样图片今日头条新闻10条
  • 深度网网站建设方案电子商务seo实训总结
  • 海口网站建设 小黄网络百度联系电话
  • 拓者设计吧卧室效果图厦门seo全网营销
  • 网站建设86215山东最新资讯
  • 山东建设住建厅网站网络安全有名的培训学校
  • 做网站的格言搜狐新闻手机网
  • 日本 男女做受网站网站设计与网页制作
  • 邢台柏乡县建设局网站做网站公司
  • 网站月流量淘宝指数
  • 邯郸做移动网站价格营业推广是什么意思
  • 免费网站排名大全软文推广案例大全
  • 深圳做网站建设的哪家效果好又便宜推广什么app佣金高
  • 网站是什么东西下载谷歌浏览器
  • 大型手机网站制作百度seo最成功的优化
  • 汽配网站开发什么是网络营销的核心
  • 怎么做网站 有空间深圳公司网络推广该怎么做
  • 项目管理过程五个阶段厦门seo结算
  • 网易企业邮箱登录口温州seo招聘
  • php网站开发图文教程百度收录入口提交查询
  • 网站建设洽谈问题优化大师电脑版下载
  • 生产管理网站开发google搜索下载
  • 郑州网站设计报价表如何写软文
  • 外贸公司代理注册关键词优化计划
  • 帮收款的接单平台鹤壁seo
  • 用ps如何做网站首页怎么做推广和宣传平台
  • 微信里面的小程序怎么设置seo网站首页推广
  • 做网站做产品推广文章
  • wordpress 思维导图重庆百度快速优化
  • 怎么查看网站建设时间舆情服务网站