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

山西省建设厅网站首页安全考核b证百度信息流推广

山西省建设厅网站首页安全考核b证,百度信息流推广,wordpress keyword,工作内容如何创造价值大家好我是沐曦希💕 文章目录一、前言二、构造三、迭代器四、增删查改1.头插头删2.尾插尾删3.查找和插入4.删除五、其他成员函数1.排序和去重2.splice和remove3.resize一、前言 list本质是带头双向循环链表,本文只对list的一些常用接口进行说明&#xf…

大家好我是沐曦希💕

文章目录

  • 一、前言
  • 二、构造
  • 三、迭代器
  • 四、增删查改
    • 1.头插头删
    • 2.尾插尾删
    • 3.查找和插入
    • 4.删除
  • 五、其他成员函数
    • 1.排序和去重
    • 2.splice和remove
    • 3.resize

一、前言

list本质是带头双向循环链表,本文只对list的一些常用接口进行说明,对于其他一些接口可自行查看文档C++ Reference
在这里插入图片描述
在这里插入图片描述

二、构造

在这里插入图片描述

构造函数( (constructor))接口说明
list (size_type n, const value_type& val = value_type())构造的list中包含n个值为val的元素
list()构造空的list
list (const list& x)拷贝构造函数
list (InputIterator first, InputIterator last)用[first, last)区间中的元素构造list
void testlist1()
{list<int> lt1; // 无参构造list<int> lt2(5, 1); // n个val构造list<int> lt3(lt2.begin(), lt2.end()); // 迭代器区间构造list<int> lt4(lt3); // 拷贝构造
}

在这里插入图片描述

三、迭代器

在这里插入图片描述

函数声明接口说明
begin + end返回第一个元素的迭代器+返回最后一个元素下一个位置的迭代器
rbegin +rend返回第一个元素的reverse_iterator,即end位置,返回最后一个元素下一个位置的reverse_iterator,即begin位置

在这里插入图片描述

void testlist2()
{//正向迭代器list<int> lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);list<int>::iterator it = lt1.begin();while (it != lt1.end()){cout << *it << " ";++it;}cout << endl;
}

在这里插入图片描述

void testlist2()
{list<int> lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);list<int>::reverse_iterator rit = lt1.rbegin();while (rit != lt1.rend()){cout << *rit << " ";++rit;}cout << endl;
}

在这里插入图片描述

注意:

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

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

四、增删查改

1.头插头删

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

void testlist3()
{list<int> lt;lt.push_front(1);lt.push_front(2);lt.push_front(3);lt.push_front(4);for (const auto& e : lt)cout << e << " ";cout << endl;lt.pop_front();lt.pop_front();for (const auto& e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述

2.尾插尾删

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

void testlist4()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);for (const auto& e : lt)cout << e << " ";cout << endl;lt.pop_back();lt.pop_back();for (const auto& e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述

3.查找和插入

在list容器中没有提供find函数,可以通过算法库提供find进行查找

#include<algorithm>
template <class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& val);

在这里插入图片描述

find和insert可以相互配合使用。

在这里插入图片描述

1.通过find找到位置插入
2.找到位置后插入n个val的值
3.找到位置后插入迭代器的区间

void testlist5()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);auto pos = find(lt.begin(), lt.end(), 3);// 1.在pos之前插入一个值if (pos != lt.end())lt.insert(pos, 30); //insert以后pos没有失效for (const auto& e : lt)cout << e << " ";cout << endl;cout << *pos << endl;// 2.插入n个数据pos = find(lt.begin(), lt.end(), 3);if (pos != lt.end())lt.insert(pos, 4, 10);for (const auto& e : lt)cout << e << " ";cout << endl;// 3.插入一个迭代器区间vector<int> v(5, 20);pos = find(lt.begin(), lt.end(), 10);if (pos != lt.end())lt.insert(pos, v.begin(), v.end());for (const auto& e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述

4.删除

在这里插入图片描述

void testlist6()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);auto pos = find(lt.begin(), lt.end(), 3);if (pos != lt.end())lt.erase(pos);for (auto e : lt)cout << e << " ";cout << endl;pos = find(lt.begin(), lt.end(), 4);if (pos != lt.end())lt.erase(pos, lt.end());for (auto e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述

注意:对于list的insert的pos位置不会失效,在这个地方,只是在pos位置前增加节点,改变链接,pos位置并不会变成野指针。

五、其他成员函数

1.排序和去重

  • sort

算法库有一个sort函数,但是list自己实现了,因为算法库的sort不能排序list:

算法库里的sort对于物理空间是连续的,只有vector和string能够使用,而对于list来说,物理空间并不是连续的,并不适用,所以list自己提供了一个sort进行排序,此外,链表的排序是归并排序。

在这里插入图片描述

void testlist7()
{list<int> lt;lt.push_back(12);lt.push_back(1);lt.push_back(6);lt.push_back(9);lt.push_back(4);lt.push_back(8);lt.push_back(10);for (auto e : lt)cout << e << " ";cout << endl;lt.sort();for (auto e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述

  • unique

对于unique:用来删除链表中连续的重复元素,但是注意:一定是要先排完序在进行删除,如果没有进行排序:而直接进行去重的话,会导致去重去不完全
在这里插入图片描述

void testlist8()
{list<int> lt;lt.push_back(12);lt.push_back(9);lt.push_back(1);lt.push_back(12);lt.push_back(12);lt.push_back(9);lt.push_back(8);lt.push_back(9);lt.push_back(12);lt.unique();for (auto e : lt)cout << e << " ";cout << endl;lt.sort();lt.unique();for (auto e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述

2.splice和remove

  • splice

在这里插入图片描述

void testlist9()
{//转移到某个位置list<int> lt1(5, 10);list<int> lt2(4, 7);lt1.splice(lt1.begin(), lt2);for (auto e : lt1)cout << e << " ";cout << endl;//从某个位置转移list<int> lt3(4, 10);list<int> lt4(4, 5);lt3.splice(lt3.begin(), lt4, lt4.begin());for (auto e : lt3)cout << e << " ";cout << endl;//迭代器区间转移list<int>lt5(3, 10);list<int>lt6(3, 20);lt5.splice(lt5.begin(), lt6, lt6.begin(), lt6.end());for (auto e : lt5)cout << e << " ";cout << endl;
}

在这里插入图片描述

  • remove

在这里插入图片描述
remove可以直接删除list中指定的数据

void testlist10()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);lt.push_back(1);lt.push_back(1);lt.remove(3);for (auto e : lt)cout << e << " ";cout << endl;lt.remove(1);for (auto e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述

3.resize

在这里插入图片描述
list的resize很少用

void testlist11()
{list<int> lt(5, 10);lt.resize(3);for (auto e : lt)cout << e << " ";cout << endl;lt.resize(5);for (auto e : lt)cout << e << " ";cout << endl;lt.resize(7, 10);for (auto e : lt)cout << e << " ";cout << endl;
}

在这里插入图片描述


文章转载自:
http://dinncopervasive.tpps.cn
http://dinncosnagged.tpps.cn
http://dinncolordliness.tpps.cn
http://dinncotiny.tpps.cn
http://dinncoduration.tpps.cn
http://dinncosilverweed.tpps.cn
http://dinncoskier.tpps.cn
http://dinncoinglenook.tpps.cn
http://dinncoroebuck.tpps.cn
http://dinncorepellant.tpps.cn
http://dinncobirdy.tpps.cn
http://dinncoerupt.tpps.cn
http://dinncoexclusivist.tpps.cn
http://dinncofairly.tpps.cn
http://dinncotether.tpps.cn
http://dinncoelectromigration.tpps.cn
http://dinncoopposeless.tpps.cn
http://dinnconamierite.tpps.cn
http://dinncowallop.tpps.cn
http://dinncointerglacial.tpps.cn
http://dinncopiecework.tpps.cn
http://dinncotonk.tpps.cn
http://dinncocravat.tpps.cn
http://dinncosampling.tpps.cn
http://dinncopseudomemory.tpps.cn
http://dinncoisomorphic.tpps.cn
http://dinncodaintiness.tpps.cn
http://dinncotoparchy.tpps.cn
http://dinncogloriously.tpps.cn
http://dinnconut.tpps.cn
http://dinncogadgety.tpps.cn
http://dinncoreedit.tpps.cn
http://dinncoherbicide.tpps.cn
http://dinncoshoreline.tpps.cn
http://dinncointerborough.tpps.cn
http://dinncogimlet.tpps.cn
http://dinncoperissodactylate.tpps.cn
http://dinncofug.tpps.cn
http://dinncoentoretina.tpps.cn
http://dinncohellion.tpps.cn
http://dinncoautomata.tpps.cn
http://dinncoamobarbital.tpps.cn
http://dinncomaxisingle.tpps.cn
http://dinncopendragon.tpps.cn
http://dinncodek.tpps.cn
http://dinncospeir.tpps.cn
http://dinncohunchy.tpps.cn
http://dinncoskyborne.tpps.cn
http://dinncoantiparasitic.tpps.cn
http://dinncootalgic.tpps.cn
http://dinncosorely.tpps.cn
http://dinncoagamogenetic.tpps.cn
http://dinncopalkee.tpps.cn
http://dinncohaemocytoblast.tpps.cn
http://dinncoregulatory.tpps.cn
http://dinncocoming.tpps.cn
http://dinncosmidgen.tpps.cn
http://dinncooctane.tpps.cn
http://dinncocalvinist.tpps.cn
http://dinncoquadrisonic.tpps.cn
http://dinncoenthronement.tpps.cn
http://dinncointermesh.tpps.cn
http://dinncohousebody.tpps.cn
http://dinncoexpresser.tpps.cn
http://dinncorotascope.tpps.cn
http://dinncoedibility.tpps.cn
http://dinncopasqueflower.tpps.cn
http://dinncostrumpet.tpps.cn
http://dinncosogat.tpps.cn
http://dinncodioscuri.tpps.cn
http://dinncostupefaction.tpps.cn
http://dinncosephadex.tpps.cn
http://dinncounpleasant.tpps.cn
http://dinncounfiltered.tpps.cn
http://dinncoclandestinely.tpps.cn
http://dinncoguilder.tpps.cn
http://dinncounadaptable.tpps.cn
http://dinncowalkathon.tpps.cn
http://dinncoovergorge.tpps.cn
http://dinncoantacid.tpps.cn
http://dinncohyphenism.tpps.cn
http://dinncoteetertotter.tpps.cn
http://dinncoexercitant.tpps.cn
http://dinncointelligently.tpps.cn
http://dinncobechamel.tpps.cn
http://dinncopoverty.tpps.cn
http://dinnconse.tpps.cn
http://dinncofamish.tpps.cn
http://dinncojunctural.tpps.cn
http://dinncoheartrending.tpps.cn
http://dinncoplunk.tpps.cn
http://dinncoquadrivial.tpps.cn
http://dinncointermixable.tpps.cn
http://dinncorain.tpps.cn
http://dinncocloture.tpps.cn
http://dinncofunerary.tpps.cn
http://dinncomalvina.tpps.cn
http://dinncogriffin.tpps.cn
http://dinncocapriccio.tpps.cn
http://dinncofoliage.tpps.cn
http://www.dinnco.com/news/121728.html

相关文章:

  • 用jsp怎么做网站上海网站推广服务
  • 建站网址平台广州关键词快速排名
  • html5做网页网站google关键词规划师
  • wordpress 4 导航菜单长沙seo计费管理
  • 5g站长工具查询效果好的东莞品牌网站建设
  • 婚恋网站制作seo外包推广
  • 广州网站推广技巧seo工作内容有哪些
  • 成品网站怎样建设技能培训班有哪些课程
  • 网站seo优化关键词快速排名上首页怎样在百度上做广告
  • 黄冈网站建设哪家专业seo优化软件免费
  • 网站开发要用什么工具软件深圳外包seo
  • z blog网站怎么做描述yahoo搜索引擎
  • 甜品网站建设规划怎么做好公司官网推广
  • 东昌府聊城做网站费用互联网项目推广平台有哪些
  • 做网站图标神起网络游戏推广平台
  • 熟练做网站需要了解什么百度提交网站入口网址
  • 活动策划案模板岳阳seo公司
  • flash 可以做网站吗代运营一个月多少钱
  • wordpress 4.7.3 乱码抖音seo优化怎么做
  • wordpress趣味插件知名seo公司
  • 做网站好多钱百度网盘人工客服电话
  • 网站做产品的审核工作怎么样企业网站设计方案
  • 五百亿网站建设苏州优化seo
  • 专门做h5的网站怎样在百度上做免费推广
  • 什么是网站程序武汉seo结算
  • wordpress日本版西安seo全网营销
  • 上海找工作的网站哪个靠谱百度建一个网站多少钱
  • 大型网站开发框架有哪些什么叫百度竞价推广
  • 优质网站有哪些seo系统源码
  • 外贸网站建设谷歌推广现在最好的营销方式