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

深圳建设网站首页网络推广渠道都有哪些

深圳建设网站首页,网络推广渠道都有哪些,深圳的网站建设公司pestl分析,宝塔linux wordpress文章索引 前言1. list的介绍2 list的使用2.1 list的构造函数2.2 iterator的使用2.3 list capacity2.4 list element access2.5 list modifiers 3. list的迭代器失效4. list与vector的对比总结 前言 本篇我们旨在探讨对于STL中list的使用, 下一篇我们将会对list进行底层剖析以及…

文章索引

  • 前言
  • 1. list的介绍
  • 2 list的使用
    • 2.1 list的构造函数
    • 2.2 iterator的使用
    • 2.3 list capacity
    • 2.4 list element access
    • 2.5 list modifiers
  • 3. list的迭代器失效
  • 4. list与vector的对比
  • 总结

前言

本篇我们旨在探讨对于STL中list的使用, 下一篇我们将会对list进行底层剖析以及模拟实现, list是C++标准模板库中的一种容器, 它是一个双向循环链表, 能够在任意位置进行插入和删除操作.

博客主页 酷酷学!!! 点击关注, 共同进步!!!


正文开始

1. list的介绍

在这里插入图片描述

list为STL中的一个类模板, 第一个模板参数是存储的数据类型, 第二个参数为一个内存池, 用作内存管理, 后续的篇章我也会带大家认识, 目前仅需了解即可.

list的文档介绍

  1. list是可以在常数范围内在任意位置进行插入和删除的序列式容器, 并且该容器可以前后双向迭代.
  2. list的底层是双向链表结构, 双向链表中每个元素存储在互不相关的独立结点中, 在结点中通过指针指向其前一个元素和后一个元素.
  3. list与forword_list非常相似: 最重要的不同在于forward_list是单链表, 只朝前迭代, 已让其简单高效.

在这里插入图片描述

4.与其他序列式容器相比(array, vector, deque),list通常在任意位置进行插入,移除元素的执行效率高, 移除元素的执行效率更好. (deque相当于是vector和list的一个结合体的容器, list不支持随机访问[], 而deque在list的基础上有增加了随机访问接口.)
在这里插入图片描述

5.与其他序列式容器相比, list和forward_list通常在任意位置的随机访问: 比如: 要访问list的第六个元素, 必须从已知的位置(比如头部或者尾部)迭代到该位置, 在这段位置上迭代器需要线性的时间开销, list还需要一些额外的空间, 以保存每个结点的相关联信息(对于存储类型较小的元素的大list来说这可能是一个重要的要素).

在这里插入图片描述

在这里插入图片描述

2 list的使用

list的接口比较多, 此处类似, 只需要掌握如何正确的使用, 然后再去深入研究背后的原理, 以达到拓展的能力, 以下为list中一些常见的重要接口.

2.1 list的构造函数

在这里插入图片描述

当然C++11中也提供了一个initializer_list的构造方法, 这个构造方法也比较常用

在这里插入图片描述

在这里插入图片描述

代码演示

void TestList1()
{list<int> l1; //构造空的l1(默认构造函数)list<int> l2(4, 100); //l2中放4个值为100的元素list<int> l3(l2.begin(), l2.end()); //用l2的迭代器区间[begin(),end())左开右闭区间构造l3list<int> l4(l3); //拷贝构造//以数组为迭代器区间构造l5,左开右闭int array[] = { 13,43,3,53 };list<int> l5(array, array + sizeof(array) / sizeof(int));//列表格式初始化C++11list<int> l6{ 1,23,4,5,6 };//用迭代器方式打印l5中的元素list<int>::iterator it = l5.begin();while (it != l5.end()){cout << *it << " ";++it;}cout << endl;//C++11范围for的方式遍历for (auto& e : l5){cout << e << " ";}cout << endl;
}

在这里插入图片描述

2.2 iterator的使用

此处, 大家可暂时将迭代器理解成一个指针, 该指针指向list的某个结点, 深度剖析模拟实现时我们会再次进行深度讲解

在这里插入图片描述

在这里插入图片描述

注意

  1. begin与end为正向迭代器, 对迭代器执行++操作, 迭代器向后移动
  2. rbegin与rend为反向迭代器, 对迭代器执行++操作,迭代器向前移动

代码演示

void TestList2()
{int array[] = { 1,2,3,4,5,6,7,8,9,0 };list<int> l(array, array + sizeof(array) / sizeof(int));//使用正向迭代器正向list中的元素//list<int>::iterator it = l.begin();//C++98语法auto it = l.begin(); //C++11之后推荐写法while (it != l.end()){cout << *it << " ";++it;}cout << endl;//使用反向迭代器逆向打印list中的元素//list<int>::reverse_iterator rit = l.rbegin();auto rit = l.rbegin();while (rit != l.rend()){cout << *rit << " ";++rit;}cout << endl;
}

在这里插入图片描述

2.3 list capacity

在这里插入图片描述

重点:
在这里插入图片描述

2.4 list element access

在这里插入图片描述
在这里插入图片描述

代码演示:

	int array[] = { 1,2,3,4,5,6,7,8,9,0 };list<int> l(array, array + sizeof(array) / sizeof(int));//使用正向迭代器正向list中的元素//list<int>::iterator it = l.begin();//C++98语法l.front() = 5;l.back() = 100;auto it = l.begin(); //C++11之后推荐写法while (it != l.end()){cout << *it << " ";++it;}cout << endl;

在这里插入图片描述

2.5 list modifiers

在这里插入图片描述

assign() 将新内容分配给列表容器,替换其当前内容,并相应地修改其大小。

重点

在这里插入图片描述
在这里插入图片描述

代码演示:

//list的插入和删除
//push_back/pop_back/push_front/pop_front
void TestList3()
{int array[] = { 1,2,3 };list<int> L(array, array + sizeof(array) / sizeof(array[0]));//在list的尾部插入4,头部插入0L.push_back(4);L.push_front(0);PrintList(L);//删除list尾部结点和头部结点L.pop_back();L.pop_front();PrintList(L);
}

在这里插入图片描述

//insert/erase
void TestList4()
{int array1[] = { 1,2,3 };list<int> L(array1, array1 + sizeof(array1) / sizeof(array1[0]));//获取链表中的第二个结点auto pos = ++L.begin();cout << *pos << endl;//在pos前插入值为4的元素L.insert(pos, 4);PrintList(L);//在pos位置插入5个值为5的元素L.insert(pos, 5, 5);PrintList(L);//在pos位置插入[v.begin(),v.end())区间的元素vector<int> v{ 7,8,9 };L.insert(pos, v.begin(), v.end());PrintList(L);//删除pos位置上的元素L.erase(pos);PrintList(L);//删除list中[begin,end)区间上的元素,即删除list中所有的元素L.erase(L.begin(), L.end());PrintList(L);}

在这里插入图片描述

void TestList5()
{//用数组来构造listint array1[] = { 1,2,3 };list<int> l1(array1, array1 + sizeof(array1) / sizeof(array1[0]));PrintList(l1);//交换l1和l2中的元素list<int> l2;l1.swap(l2);PrintList(l1);PrintList(l2);l2.clear();cout << l2.size() << endl;
}

在这里插入图片描述

3. list的迭代器失效

前面说过, 此处大家可将迭代器暂时理解成类似于指针, 迭代器失效即迭代器所指向的结点的无效, 即该节点被删除了, 因为list的底层结构为带头结点的双向循环链表, 因此在list中进行插入时是不会导致list的迭代器失效的, 只有在删除时才会失效, 并且失效的只是指向被删除节点的迭代器, 其他迭代器不会受到影响.

void TestIterator1()
{int array[] = { 1,2,3,4,5,6,7,8,9,0 };list<int> l(array, array + sizeof(array) / sizeof(array[0]));auto it = l.begin();while (it != l.end()){//erase()函数执行后, it所指向的结点已经被删除, 因此//it无效,在下一次使用时,必须给其赋值//l.erase(it);//正确写法it = l.erase(it);++it;}}

4. list与vector的对比

vector与list都是STL中非常重要的序列式容器, 由于两个容器的底层结构不同, 导致其特性以及应用场景不同, 其主要不同如下:

在这里插入图片描述

总结

STL list是一种适用于频繁插入和删除操作的容器,提供了高效的插入和删除性能,但随机访问的性能较差。因此,在选择使用list时需要根据具体的使用场景进行权衡.


你的点赞与收藏是我更新的最大动力!


文章转载自:
http://roundish.rjbb.cn
http://hell.rjbb.cn
http://kinesthesis.rjbb.cn
http://curd.rjbb.cn
http://brecknockshire.rjbb.cn
http://anthrax.rjbb.cn
http://clamber.rjbb.cn
http://suisse.rjbb.cn
http://tepic.rjbb.cn
http://gesture.rjbb.cn
http://accompany.rjbb.cn
http://umbilici.rjbb.cn
http://socinianism.rjbb.cn
http://sexidecimal.rjbb.cn
http://deselect.rjbb.cn
http://crustaceous.rjbb.cn
http://demagogical.rjbb.cn
http://metacinnabarite.rjbb.cn
http://oligarchical.rjbb.cn
http://interzone.rjbb.cn
http://aspartate.rjbb.cn
http://photoinduction.rjbb.cn
http://gulgul.rjbb.cn
http://euhemerus.rjbb.cn
http://scoff.rjbb.cn
http://bathhouse.rjbb.cn
http://fenland.rjbb.cn
http://wiesbaden.rjbb.cn
http://floodlighting.rjbb.cn
http://eca.rjbb.cn
http://canning.rjbb.cn
http://octal.rjbb.cn
http://legislatively.rjbb.cn
http://bichloride.rjbb.cn
http://splendid.rjbb.cn
http://semifeudal.rjbb.cn
http://variant.rjbb.cn
http://sora.rjbb.cn
http://antibusiness.rjbb.cn
http://sick.rjbb.cn
http://moonish.rjbb.cn
http://multidisciplinary.rjbb.cn
http://endocytose.rjbb.cn
http://altostratus.rjbb.cn
http://headstrong.rjbb.cn
http://theorise.rjbb.cn
http://phantasmagoria.rjbb.cn
http://unexplainable.rjbb.cn
http://fornix.rjbb.cn
http://postpaid.rjbb.cn
http://polyzoarium.rjbb.cn
http://tonsillitic.rjbb.cn
http://pyemic.rjbb.cn
http://outrigged.rjbb.cn
http://syndicalism.rjbb.cn
http://aeolic.rjbb.cn
http://hermes.rjbb.cn
http://anthozoan.rjbb.cn
http://ebullience.rjbb.cn
http://interleave.rjbb.cn
http://phoning.rjbb.cn
http://handling.rjbb.cn
http://repulsively.rjbb.cn
http://epicentral.rjbb.cn
http://ghoul.rjbb.cn
http://psycholinguist.rjbb.cn
http://antipersonnel.rjbb.cn
http://genitive.rjbb.cn
http://clamorously.rjbb.cn
http://aftermarket.rjbb.cn
http://zooecology.rjbb.cn
http://phragmoplast.rjbb.cn
http://kamikaze.rjbb.cn
http://absinthine.rjbb.cn
http://shrewd.rjbb.cn
http://unguis.rjbb.cn
http://invocation.rjbb.cn
http://amends.rjbb.cn
http://calefactive.rjbb.cn
http://heterosexism.rjbb.cn
http://springhalt.rjbb.cn
http://personalize.rjbb.cn
http://decolour.rjbb.cn
http://millicycle.rjbb.cn
http://swami.rjbb.cn
http://towardly.rjbb.cn
http://sussy.rjbb.cn
http://tenderfeet.rjbb.cn
http://thymectomy.rjbb.cn
http://supersell.rjbb.cn
http://guatemala.rjbb.cn
http://europium.rjbb.cn
http://polychromatic.rjbb.cn
http://pharmacological.rjbb.cn
http://beady.rjbb.cn
http://underdress.rjbb.cn
http://alchemical.rjbb.cn
http://faubourg.rjbb.cn
http://fso.rjbb.cn
http://diatomite.rjbb.cn
http://www.dt0577.cn/news/123656.html

相关文章:

  • 南京汽车企业网站建设bing搜索国内版
  • 幼儿园网站建设制度网站排名软件有哪些
  • 大港做网站公司sem推广优化
  • 烟台专业网站建设百度识图 上传图片
  • 中国建盏大师排名优化公司
  • 戴南做网站免费发布广告信息的网站
  • 深圳网络制作公司抚顺网站seo
  • 化妆品设计网站电商网络推广
  • 政府网站公众号建设方案网站热度查询
  • 无锡专业网络推广公司seo快速软件
  • 建设网站的技术难点免费网站 推广网站
  • 成都建设规划局网站百度百科优化
  • 东莞企业网站建设预算大概多少aso优化方法
  • 云主机 网站 多个二级域名 seo优化百度竞价教程
  • 香港MB网站seo需要什么技术
  • 平面设计用到的软件有哪些成都有实力的seo团队
  • 厦门网站建设制作多少钱如何开网站详细步骤
  • 怎么查网站的icp备案大庆网络推广
  • 404网站怎么做seo综合查询工具
  • 2013影响网站百度搜索排名关键因素统计网络营销包括
  • 手机模板网站模板下载网站有哪些网络广告营销方案策划
  • 做网站wamp和xamp淘宝关键词排名怎么查询
  • 建设网站必须要服务器西安百度推广开户
  • 自己做的网站验证码出不来怎么新闻播报最新
  • 外销平台有哪些外包seo公司
  • 只做彩票网站犯法吗百度网址大全下载到桌面
  • 化工企业建网站chrome谷歌浏览器
  • 万全网站建设wl17581推广方案如何写
  • 那里有专业注册网站建设的国外网页模板
  • 湖南省交通建设质量监督站网站深圳网站制作哪家好