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

自动化产品的网站建设logo设计公司地址

自动化产品的网站建设,logo设计公司地址,自然资源网站官网,网络营销的含义是什么cpp中常见的容器类有vector、list、deque、map、set、unordered_map和unordered_set。 下面将举例直接说明各个容器的使用方法。 文章目录综合示例1. vector:动态数组,支持随机访问2. list:双向链表,支持双向遍历和插入删除3. de…

cpp中常见的容器类有vector、list、deque、map、set、unordered_map和unordered_set。

下面将举例直接说明各个容器的使用方法。

文章目录

    • 综合示例
      • 1. vector:动态数组,支持随机访问
      • 2. list:双向链表,支持双向遍历和插入删除
      • 3. deque:双端队列,支持首尾插入删除和随机访问
      • 4. map:红黑树实现的关联数组,支持按键访问和遍历
      • 5. set:红黑树实现的集合,支持按值访问和遍历
      • 6. unordered_map:哈希表实现的关联数组,支持按键访问和遍历
      • 7. unordered_set:哈希表实现的集合,支持按值访问和遍历
    • 检索方法示例
      • 1. vector:根据下标检索
      • 2. deque:根据下标检索
      • 3. set:根据值检索
      • 4. map:根据值检索
      • 5. unordered_set:根据值检索
      • 6. unordered_map:根据值检索

综合示例

1. vector:动态数组,支持随机访问

#include <iostream>
#include <vector>using namespace std;int main()
{vector<int> v;// 添加元素v.push_back(1);v.push_back(2);v.push_back(3);// 遍历元素for (auto it = v.begin(); it != v.end(); ++it){cout << *it << " ";}cout << endl;// 访问元素cout << v[0] << endl;cout << v.at(1) << endl;// 删除元素v.erase(v.begin() + 1);// 大小和容量cout << v.size() << endl;cout << v.capacity() << endl;return 0;
}

2. list:双向链表,支持双向遍历和插入删除

#include <iostream>
#include <list>using namespace std;int main()
{list<int> l;// 添加元素l.push_back(1);l.push_back(2);l.push_back(3);l.push_front(0);// 遍历元素for (auto it = l.begin(); it != l.end(); ++it){cout << *it << " ";}cout << endl;// 访问元素cout << l.front() << endl;cout << l.back() << endl;// 删除元素l.pop_front();// 大小cout << l.size() << endl;return 0;
}

3. deque:双端队列,支持首尾插入删除和随机访问

#include <iostream>
#include <deque>using namespace std;int main()
{deque<int> d;// 添加元素d.push_back(1);d.push_front(0);d.push_back(2);// 遍历元素for (auto it = d.begin(); it != d.end(); ++it){cout << *it << " ";}cout << endl;// 访问元素cout << d[0] << endl;cout << d.at(1) << endl;// 删除元素d.pop_front();// 大小cout << d.size() << endl;return 0;
}

4. map:红黑树实现的关联数组,支持按键访问和遍历

#include <iostream>
#include <map>using namespace std;int main()
{map<string, int> m;// 添加元素m["apple"] = 1;m["banana"] = 2;m.insert(make_pair("orange", 3));// 遍历元素for (auto it = m.begin(); it != m.end(); ++it){cout << it->first << " " << it->second << endl;}// 访问元素cout << m["apple"] << endl;// 删除元素m.erase("banana");// 大小cout << m.size() << endl;return 0;
}

5. set:红黑树实现的集合,支持按值访问和遍历

#include <iostream>
#include <set>using namespace std;int main()
{set<int> s;// 添加元素s.insert(1);s.insert(2);s.insert(3);// 遍历元素for (auto it = s.begin(); it != s.end(); ++it){cout << *it << " ";}cout << endl;// 访问元素auto it = s.find(2);if (it != s.end()){cout << *it << endl;}// 删除元素s.erase(3);// 大小cout << s.size() << endl;return 0;
}

6. unordered_map:哈希表实现的关联数组,支持按键访问和遍历

#include <iostream>
#include <unordered_map>using namespace std;int main()
{unordered_map<string, int> um;// 添加元素um["apple"] = 1;um["banana"] = 2;um.insert(make_pair("orange", 3));// 遍历元素for (auto it = um.begin(); it != um.end(); ++it){cout << it->first << " " << it->second << endl;}// 访问元素auto it = um.find("apple");if (it != um.end()){cout << it->second << endl;}// 删除元素um.erase("banana");// 大小cout << um.size() << endl;return 0;
}

7. unordered_set:哈希表实现的集合,支持按值访问和遍历

#include <iostream>
#include <unordered_set>using namespace std;int main()
{unordered_set<int> us;// 添加元素us.insert(1);us.insert(2);us.insert(3);// 遍历元素for (auto it = us.begin(); it != us.end(); ++it){cout << *it << " ";}cout << endl;// 访问元素auto it = us.find(2);if (it != us.end()){cout << *it << endl;}// 删除元素us.erase(3);// 大小cout << us.size() << endl;return 0;
}

检索方法示例

  • 根据下标检索的容器类有vectordeque
  • 根据值检索的容器类有setmapunordered_setunordered_map

(感觉主要靠容器.find()方法、容器.count()方法或者还可以用algorithm库里面的find)

1. vector:根据下标检索

#include <iostream>
#include <vector>using namespace std;int main()
{vector<int> v = {1, 2, 3};// 访问元素cout << v[0] << endl;cout << v.at(1) << endl;// 判断元素是否在容器内if (v.size() > 0 && v[0] == 1){cout << "1 is in the vector." << endl;}return 0;
}

2. deque:根据下标检索

#include <iostream>
#include <deque>using namespace std;int main()
{deque<int> d = {1, 2, 3};// 访问元素cout << d[0] << endl;cout << d.at(1) << endl;// 判断元素是否在容器内if (d.size() > 0 && d[0] == 1){cout << "1 is in the deque." << endl;}return 0;
}

3. set:根据值检索

#include <iostream>
#include <set>using namespace std;int main()
{set<int> s = {1, 2, 3};// 查找元素auto it = s.find(2);if (it != s.end()){cout << *it << " is in the set." << endl;}// 判断元素是否在容器内if (s.count(1) > 0){cout << "1 is in the set." << endl;}return 0;
}

4. map:根据值检索

#include <iostream>
#include <map>using namespace std;int main()
{map<string, int> m = {{"apple", 1}, {"banana", 2}, {"orange", 3}};// 查找元素auto it = m.find("banana");if (it != m.end()){cout << it->second << " is in the map." << endl;}// 判断元素是否在容器内if (m.count("apple") > 0){cout << "apple is in the map." << endl;}return 0;
}

5. unordered_set:根据值检索

#include <iostream>
#include <unordered_set>using namespace std;int main()
{unordered_set<int> us = {1, 2, 3};// 查找元素auto it = us.find(2);if (it != us.end()){cout << *it << " is in the unordered_set." << endl;}// 判断元素是否在容器内if (us.count(1) > 0){cout << "1 is in the unordered_set." << endl;}return 0;
}

6. unordered_map:根据值检索

#include <iostream>
#include <unordered_map>using namespace std;int main()
{unordered_map<string, int> um = {{"apple", 1}, {"banana", 2}, {"orange", 3}};// 查找元素auto it = um.find("banana");if (it != um.end()){cout << it->second << " is in the unordered_map." << endl;}// 判断元素是否在容器内if (um.count("apple") > 0){cout << "apple is in the unordered_map." << endl;}return 0;
}
http://www.sczhlp.com/news/114963/

相关文章:

  • 北京市专业网站建设国内最便宜机票网站建设
  • 网站备案 是域名还是空间中文网站建设
  • 新手怎么建立自己的网站素材之家
  • 广州建设专业网站网页设计与制作教案详案
  • 做网站的好公司有哪些烟台网站建设联系电话
  • 小游戏网站网址《关于加快网站群建设的通知》
  • 自己做个网站怎么做asp装修公司网站
  • 国内AI云市场:挤不进前三,生存将成问题!
  • 亚马逊网站特点网站建设新手教学视频
  • 做网站怎样做才有百度快照cdn 加速 网站
  • 电力建设工程最好的网站诚信企业查询系统
  • 如何查看网站开发源码用wordpress教程视频
  • 做网站的公司利润五一自驾游去哪里好
  • 荣县网站开发阅读网站怎样做
  • 注册域名之后怎么建网站用php做网站需要什么软件
  • 做网站用什么格式做好福州 网站定制设计
  • 建设网站的费用明细大概有哪些wordpress 详解
  • 指纹锁在什么网站做宣传好如何免费注册网址
  • 大牌印花图案设计网站广东建设行业信息网
  • 资讯门户类网站有哪些室内设计意向图网站
  • 济南 建网站效果图设计师主要做什么
  • 网站集约化建设需求个人网站怎么做支付
  • 网站改版需求分析wordpress 5.1不提示自动更新
  • 公司网站建设后期维护门户网站做等保需要备案哪些
  • 网站维护工作是做啥龙华网站建设销售员
  • 推广的网站百度指数如何分析
  • 唐山自助建站宁波公司地址
  • 手机棋牌网站大全贵州省住房和城乡建设厅网站报名网
  • 创建一个网站需要多少钱夏家胡同网站建设
  • 专业建站公司费用wordpress 文章地址