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

卓商网站建设网站程序备份方法

卓商网站建设,网站程序备份方法,国外服务器免备案,一元购物app大家好我是沐曦希#x1f495; 文章目录一、前言二、构造三、迭代器四、增删查改1.头插头删2.尾插尾删3.查找和插入4.删除五、其他成员函数1.排序和去重2.splice和remove3.resize一、前言 list本质是带头双向循环链表#xff0c;本文只对list的一些常用接口进行说明#xf… 大家好我是沐曦希 文章目录一、前言二、构造三、迭代器四、增删查改1.头插头删2.尾插尾删3.查找和插入4.删除五、其他成员函数1.排序和去重2.splice和remove3.resize一、前言 list本质是带头双向循环链表本文只对list的一些常用接口进行说明对于其他一些接口可自行查看文档C Reference 二、构造 构造函数 (constructor)接口说明list (size_type n, const value_type val value_type())构造的list中包含n个值为val的元素list()构造空的listlist (const list x)拷贝构造函数list (InputIterator first, InputIterator last)用[first, last)区间中的元素构造list void testlist1() {listint lt1; // 无参构造listint lt2(5, 1); // n个val构造listint lt3(lt2.begin(), lt2.end()); // 迭代器区间构造listint lt4(lt3); // 拷贝构造 }三、迭代器 函数声明接口说明begin end返回第一个元素的迭代器返回最后一个元素下一个位置的迭代器rbegin rend返回第一个元素的reverse_iterator,即end位置返回最后一个元素下一个位置的reverse_iterator,即begin位置void testlist2() {//正向迭代器listint lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);listint::iterator it lt1.begin();while (it ! lt1.end()){cout *it ;it;}cout endl; }void testlist2() {listint lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);lt1.push_back(4);listint::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() {listint 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() {listint 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进行查找 #includealgorithm template class InputIterator, class T InputIterator find (InputIterator first, InputIterator last, const T val);find和insert可以相互配合使用。 1.通过find找到位置插入 2.找到位置后插入n个val的值 3.找到位置后插入迭代器的区间 void testlist5() {listint 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.插入一个迭代器区间vectorint 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() {listint 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() {listint 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() {listint 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() {//转移到某个位置listint lt1(5, 10);listint lt2(4, 7);lt1.splice(lt1.begin(), lt2);for (auto e : lt1)cout e ;cout endl;//从某个位置转移listint lt3(4, 10);listint lt4(4, 5);lt3.splice(lt3.begin(), lt4, lt4.begin());for (auto e : lt3)cout e ;cout endl;//迭代器区间转移listintlt5(3, 10);listintlt6(3, 20);lt5.splice(lt5.begin(), lt6, lt6.begin(), lt6.end());for (auto e : lt5)cout e ;cout endl; }remove remove可以直接删除list中指定的数据 void testlist10() {listint 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() {listint 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://www.hkea.cn/news/14588398/

相关文章:

  • 网站推广的途径和要点企业信息系统有哪些
  • 网站开发的方法有哪些0基础wordpress
  • 中国新闻发布优化工具箱下载
  • 工人找工作哪个网站好wordpress历史版本下载
  • 北京 网站建设 公wordpress后台是什么样的
  • 环保设备网站怎么做黄页官网
  • 关键词查询的分析网站黄页88网是什么性质的网站
  • 合肥房产网365游戏优化大师官方下载
  • 淘宝网站设计模板下载开发一个物流app需要多少钱
  • python做的网站源码代理网页游戏代理
  • 高端网站开发建设网站平台建设经费预算
  • 常州网页模板建站五屏网站建设哪家有
  • 海城市建设局网站对网站建设的意见建议
  • 商城网站功能模块有哪些福州做网站多少钱
  • 设计网站 知乎软件开发文档的基本格式
  • 网站页面设计流程页面设计的突出主体原则
  • 网站备案需要注意什么wordpress08
  • 江苏新宁建设集团网站山东省工程建设协会网站
  • 网站的建设与管理自考美容营销型网站
  • 网络销售网站设置施工合同在哪个建设网站下载
  • 广州seo群wordpress优化搜索引擎
  • 做网站建设多少钱网站规划与建设的案例分析
  • 做购物网站哪个cms好用成为网站有哪些网址?
  • 江门网站制作培训学校国土资源局网站建设制度
  • 专业做网站十大免费ppt网站下载
  • 北京海淀区网站建设网站扩展虚拟空间
  • 宁夏建设造价网站discuz应用中心
  • 免费建网站程序页面设计方案
  • 哈尔滨手机建站模板物流公司排名
  • 汕头网站建设公司牛商网网站建设多少钱