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

北京h5网站制作建设岗位考试网站

北京h5网站制作,建设岗位考试网站,上海网络推广公司排名,ASP.NET实用网站开发答案list容器是一个双向链表容器#xff0c;可以高效地进行插入删除元素#xff0c;但是不能随机存取元素#xff08;不支持at()和[]操作符#xff09;。一、list容器的对象构造方法list对象采用模板类的默认构造形式例如listT lst#xff1b;#includeiostream可以高效地进行插入删除元素但是不能随机存取元素不支持at()和[]操作符。一、list容器的对象构造方法list对象采用模板类的默认构造形式例如listT lst#includeiostream #includelist using namespace std; int main() {int arr[]{0,1,2,3,4};listint lstInt;listfloat lstFloat;liststring listString;listint::iterator t1;listint::iterator t2;lstInt.assign(arr,arr5);lstInt.push_back(5);//在容器尾部插入元素lstInt.push_back(5);//在容器尾部删除元素lstInt.pop_back();lstInt.push_front(0);//在容器头部插入元素lstInt.push_front(0);lstInt.pop_front();//在容器头部删除元素t1lstInt.begin(); t2lstInt.end(); // 正确写法 for(;t1!t2;t1){cout*t1;}coutendl;// 错误写法 // for(;t1t2;t1) // { // cout*t1; // } // coutendl;//输出0012345 return 0; }list对象的带参构造方式listT lst(beg,end该构造函数将区间[beg,end)中的元素拷贝给本身。beg,end是数组元素的地址。listT list(n,elem该构造函数将n个elem拷贝给本身。listT lst1(lst2拷贝构造函数#includeiostream #includelist using namespace std; int main() {int arr[]{0,1,2,3,4};listint::iterator t;//1、list对象带参数构造 //正确写法 listint lst1(arr,arr5); //建立一个存放int的list容器,初始为01234 listint lst2(lst1.begin(),lst1.end()); //建立一个存放int的list容器初始为01234 listint lst3(3,100); listint lst4(lst1); for(tlst1.begin();t!lst1.end();t){cout*t ;}coutendl;for(tlst2.begin();t!lst2.end();t){cout*t ;}coutendl;for(tlst3.begin();t!lst3.end();t){cout*t ;}coutendl;for(tlst4.begin();t!lst4.end();t){cout*t ;}coutendl;//输出 //0 1 2 3 4 //0 1 2 3 4 //100 100 100 //0 1 2 3 4 return 0; } 二、list与迭代器list容器的迭代器是双向迭代器。list.begin();返回容器第一个元素的迭代器。list.end();返回容器最后一个元素之后的迭代器。list.rbegin();返回容器倒数第一个元素的迭代器。list.rend();返回容器倒数最后一个元素后面的迭代器。#includeiostream #includelist using namespace std; int main() {int arr[]{0,1,2,3,4};listint lstInt;listint::iterator t1;listint::iterator t2;lstInt.assign(arr,arr5);t1lstInt.begin(); t2lstInt.end(); // 正确写法 for(;t1!t2;t1){cout*t1;}coutendl;// 错误写法 // for(;t1t2;t1) // { // cout*t1; // } // coutendl;//输出01234return 0; }三、list容器的赋值1、list.assign(beg,end) 将区间[beg,end)中的元素拷贝给本身。2、list.assign(n,elem)将n个elem拷贝给本身。3、list operator(const list vec)重载等号操作符。4、list.swap(vec)将vec与本身的元素交换。#includeiostream #includelist using namespace std; int main() {int arr[]{0,1,2,3,4};listint::iterator t;listint lst1; listint lst2; listint lst3; lst1.assign(arr,arr5);lst2.assign(3,100);lst3lst1;lst2.swap(lst1);for(tlst1.begin();t!lst1.end();t){cout*t ;}coutendl;for(tlst2.begin();t!lst2.end();t){cout*t ;}coutendl;for(tlst2.begin();t!lst2.end();t){cout*t ;}coutendl; //输出 //100 100 100 //0 1 2 3 4 //0 1 2 3 4 return ; } 四、list容器的大小list.size()返回容器中元素的个数list.empty()判断容器是否为空list.resize(num)重新指定容器长度若比之前的长度长超出部分填充默认值若比之前的长度短删除超出部分元素。list.resize(num,elem)重新指定容器长度若比之前的长度长超出部分填充指定值若比之前的长度短删除超出部分元素。五、list容器元素的插入list.insert(poselem在pos位置插入一个elem元素返回新元素的位置迭代器类型list.insert(posn, elem在pos位置插入n个elem元素无返回值list.insert(posbeg, end在pos位置插入[begend区间的数据无返回值。六、list容器的删除1、list.clear();移除容器的所有数据2、list.erase(beg,end);删除[beg,end区间的数据返回下一个数据的位置。3、list.erase(pos);删除pos位置的元素返回下一个数据的位置。4、list.remove(elem);删除容器里所有值为elem的元素。#includeiostream #includelist using namespace std; int main() {int arr[]{0,1,2,3,4};listint lstInt;listint::iterator t1;listint::iterator t2;listint::iterator t3;lstInt.assign(arr,arr5);t1lstInt.begin(); for(;t1!lstInt.end();t1){cout*t1;}coutendl;//01234lstInt.clear();lstInt.push_front(5);lstInt.push_front(6);lstInt.push_front(7);lstInt.push_front(8);for(t1lstInt.begin();t1!lstInt.end();t1){cout*t1;}coutendl;//8765t2lstInt.begin();t3lstInt.begin();t3;t3;lstInt.erase(t2,t3);for(t1lstInt.begin();t1!lstInt.end();t1){cout*t1;}coutendl;//85lstInt.push_front(5);lstInt.push_front(6);lstInt.push_front(7);lstInt.push_front(8);lstInt.remove(5);for(t1lstInt.begin();t1!lstInt.end();t1){cout*t1;}coutendl;//8768//输出 //01234 //8765 //85 //8768return 0; }七、其他lst.reverse();反转列表#includeiostream #includelist using namespace std; int main() {int arr[]{0,1,2,3,4};listint lstInt;listint::iterator t1;listint::iterator t2;lstInt.assign(arr,arr5);lstInt.reverse();t1lstInt.begin(); t2lstInt.end(); for(;t1!t2;t1){cout*t1;}coutendl; // 输出43210 return 0; }2、删除结点导致迭代器失效#includeiostream #includelist using namespace std; int main() {int arr[]{0,1,2,3,4,4,4,4,4,4,4,5,5,6,6};listint lstInt;listint::iterator t1;listint::iterator t2;lstInt.assign(arr,arr15);t1lstInt.begin(); t2lstInt.end(); //因为list容器使用不连续分配的内存并且它的erase方法会返回下一个有效的迭代器所有遍历删除结点可以有以下方式 //方法1 for(;t1!t2;){if(*t14){t1lstInt.erase(t1);}else{t1;}}//方法2for(;t1!t2;t1){if(*t14){lstInt.erase(t1);}}t1lstInt.begin(); t2lstInt.end(); for(;t1!t2;t1){cout*t1 ;}coutendl; //输出0 1 2 3 5 5 6 6 return 0; }
http://www.w-s-a.com/news/491392/

相关文章:

  • 南京网站定制开发商城网站免费模板
  • 青海学会网站建设公司照片组合拼图
  • 中国建设银行福清分行网站爱站网权重查询
  • 外贸通网站建设网站建设7个主要流程图
  • 元气森林网络营销方式医疗网站优化怎么做
  • 手机网站制作报价表做网站公司做网站公司
  • 湖州网站设计吉林网站建设哪家好
  • 做存储各种环境信息的网站使用tag的网站
  • 阿里云用ip做网站网站开发员属于
  • 外链网盘下载南宁seo推广优化
  • 网站的推广方案有哪些此网站可能有
  • wordpress更改链接后网站打不开一键生成个人网站
  • 网站建设后台有哪些东西前端开发培训一般多少钱
  • 高端建设网站公司网站开发 源码
  • 企业网站的劣势园林景观设计公司简介范文
  • 网站建设程序招聘东营建设信息网登录
  • o2o是什么意思通俗讲seo与网站优化 pdf
  • 外贸网站外包一般建设一个网站多少钱
  • 抄袭别人网站的前端代码合法吗网络促销策略
  • 用wordpress制作网站做资源网站
  • wordpress 发布网站南宁网站建设网站
  • 职业生涯规划大赛心得贵阳哪家网站做优化排名最好
  • wordpress 图片懒加载北京网站优化和推广
  • 深圳网站建设工作一个dede管理两个网站
  • 被禁止访问网站怎么办中国建筑网官网查询系统
  • 网站管理运营建设网贷网站
  • 深圳市龙岗区住房和建设局网站怎么给网站做404界面
  • 设计类网站网站系统 建设和软件岗位职责
  • 网站后台打开慢站长之家网址ip查询
  • 图书馆网站设计方案家具设计作品