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

企业网站申请流程湖南平台网站建设设计

企业网站申请流程,湖南平台网站建设设计,一个类引用另一个类的方法,商贸信息网站目录 一、介绍 二、list的常用操作 1、构造 2、迭代器 3、元素访问 4、容量操作 一、介绍 std::list文档链接 list是可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。list的底层是双向链表结构,双向链表中每个…

目录

一、介绍

二、list的常用操作

1、构造

2、迭代器

3、元素访问

4、容量操作


  一、介绍

std::list文档链接
  1. list是可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。
  2. list的底层是双向链表结构,双向链表中每个元素存储在互不相关的独立节点中,在节点中通过指针指向其前一个元素和后一个元素。
  3. list与forward_list非常相似:最主要的不同在于forward_list是单链表,只能朝前迭代,已让其更简单高效。
  4. 与其他的序列式容器相比(array,vector,deque),list通常在任意位置进行插入、移除元素的执行效率更好。
  5. 与其他序列式容器相比,list和forward_list最大的缺陷是不支持任意位置的随机访问,比如:要访问list的第6个元素,必须从已知的位置(比如头部或者尾部)迭代到该位置,在这段位置上迭代需要线性的时间开销;list还需要一些额外的空间,以保存每个节点的相关联信息(对于存储类型较小元素的大list来说这可能是一个重要的因素)。
void test1()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);list<int>::iterator it = lt.begin();while (it != lt.end()){cout << *it << " ";++it;}cout << endl;for (auto e : lt){cout << e << " ";}cout << endl;
}int main()
{test1();return 0;
}

二、list的常用操作

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

1、构造

构造函数((constructor)

接口说明

list (size_type n,const value_type&val =value_type()

构造的list中包含n个值为val的元素

list()

构造空的list

list (const list&x)

拷贝构造函数

list (Inputlterator first,Inputlterator last)

用[first,last]区间中的元素构造list

// list的构造
void TestList1()
{list<int> l1;                         // 构造空的l1list<int> l2(4, 100);                 // l2中放4个值为100的元素list<int> l3(l2.begin(), l2.end());  // 用l2的[begin(), end())左闭右开的区间构造l3list<int> l4(l3);                    // 用l3拷贝构造l4// 以数组为迭代器区间构造l5int array[] = { 16,2,77,29 };list<int> l5(array, array + sizeof(array) / sizeof(int));// 列表格式初始化C++11list<int> l6{ 1,2,3,4,5 };// 用迭代器方式打印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;
}
int main()
{TestList1();return 0;
}

2、迭代器

此处,大家可暂时将迭代器理解成一个指针,该指针指向list中的某个节点。

函数声明

接口说明

begin +

end

返回第一个元素的迭代器+返回最后一个元素下一个位置的迭代器

rbegin +

rend

返回第一个元素的reverse_iterator,即end位置,返回最后一个元素下一个位置的 reverse_iterator,即begin位置

// list迭代器的使用
// 注意:遍历链表只能用迭代器和范围for
void PrintList(const list<int>& l)
{// 注意这里调用的是list的 begin() const,返回list的const_iterator对象for (list<int>::const_iterator it = l.begin(); it != l.end(); ++it){cout << *it << " ";// *it = 10; 编译不通过}cout << endl;
}void TestList2()
{int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };list<int> l(array, array + sizeof(array) / sizeof(array[0]));// 使用正向迭代器正向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;
}

【注意】

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

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

3、元素访问

函数声明

接口说明

front

返回list的第一个节点中值的引用

back

返回list的最后一个节点中值的引用

4、容量操作

函数声明

接口说明

empty

检测list是否为空,是返回true,否则返回false

size

返回list中有效节点的个数

push_front

list首元素前插入值为val的元素

pop_front

删除list中第一个元素

push_back

list尾部插入值为val的元素

pop_back

删除list中最后一个元素

insert

list position 位置中插入值为val的元素

erase

删除list position位置的元素

swap

交换两个list中的元素

clear

清空list中的有效元素

// 打印列表
void PrintList(const list<int>& l)
{for (list<int>::const_iterator it = l.begin(); it != l.end(); ++it){cout << *it << " ";}cout << endl;
}// 测试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);
}// 测试list的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);
}// 测试list的resize/swap/clear操作
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);cout << "l1:";PrintList(l1);cout << "l2:";PrintList(l2);// 将l2中的元素清空l2.clear();cout << l2.size() << endl;
}int main()
{cout << "执行TestList3()" << endl;TestList3();cout << endl;cout << "执行TestList4()" << endl;TestList4();cout << endl;cout << "执行TestList5()" << endl;TestList5();return 0;
}

 


文章转载自:
http://smogout.jftL.cn
http://daggerboard.jftL.cn
http://kiaugh.jftL.cn
http://shortall.jftL.cn
http://conterminal.jftL.cn
http://cupferron.jftL.cn
http://cockfight.jftL.cn
http://nortriptyline.jftL.cn
http://profound.jftL.cn
http://capitalise.jftL.cn
http://handfast.jftL.cn
http://vav.jftL.cn
http://scientifically.jftL.cn
http://jingoist.jftL.cn
http://phtisis.jftL.cn
http://stomp.jftL.cn
http://included.jftL.cn
http://mlf.jftL.cn
http://unperturbed.jftL.cn
http://confederacy.jftL.cn
http://horsepox.jftL.cn
http://hairbrush.jftL.cn
http://sprit.jftL.cn
http://subtilize.jftL.cn
http://reoccupy.jftL.cn
http://extrajudicial.jftL.cn
http://gapy.jftL.cn
http://sheepmeat.jftL.cn
http://introspection.jftL.cn
http://unassailable.jftL.cn
http://concoctive.jftL.cn
http://shiva.jftL.cn
http://bollocks.jftL.cn
http://funerary.jftL.cn
http://amoroso.jftL.cn
http://bespatter.jftL.cn
http://yawningly.jftL.cn
http://dabble.jftL.cn
http://ecaudate.jftL.cn
http://rhizophilous.jftL.cn
http://units.jftL.cn
http://reposal.jftL.cn
http://segetal.jftL.cn
http://bootblack.jftL.cn
http://chondrosarcoma.jftL.cn
http://vocable.jftL.cn
http://paedologist.jftL.cn
http://justifiability.jftL.cn
http://forestry.jftL.cn
http://eonism.jftL.cn
http://trident.jftL.cn
http://strategist.jftL.cn
http://trichomonal.jftL.cn
http://douceur.jftL.cn
http://superfamily.jftL.cn
http://teutophil.jftL.cn
http://tallinn.jftL.cn
http://rhizotomy.jftL.cn
http://mouldwarp.jftL.cn
http://esb.jftL.cn
http://paraparesis.jftL.cn
http://asc.jftL.cn
http://cumulous.jftL.cn
http://leaden.jftL.cn
http://yegg.jftL.cn
http://traditional.jftL.cn
http://dunt.jftL.cn
http://nurseryman.jftL.cn
http://retribalize.jftL.cn
http://rhyming.jftL.cn
http://fishbed.jftL.cn
http://leila.jftL.cn
http://logographer.jftL.cn
http://inconvenience.jftL.cn
http://regraft.jftL.cn
http://lousewort.jftL.cn
http://absterge.jftL.cn
http://inflate.jftL.cn
http://nacrite.jftL.cn
http://galyak.jftL.cn
http://pinto.jftL.cn
http://thucydides.jftL.cn
http://penitent.jftL.cn
http://oxonian.jftL.cn
http://sexploitation.jftL.cn
http://spree.jftL.cn
http://gyral.jftL.cn
http://confront.jftL.cn
http://ka.jftL.cn
http://bookhunter.jftL.cn
http://flavourful.jftL.cn
http://ruana.jftL.cn
http://nicol.jftL.cn
http://volcanologist.jftL.cn
http://cysteamine.jftL.cn
http://pyrogenation.jftL.cn
http://softland.jftL.cn
http://unsettle.jftL.cn
http://filch.jftL.cn
http://upslope.jftL.cn
http://www.dt0577.cn/news/94594.html

相关文章:

  • 凡科网做网站好吗百度客户端电脑版
  • 宁波网站优化价格营销是做什么
  • 如何做淘宝客独立网站热点事件营销案例
  • 华为荣耀官网手机商城aso优化什么意思是
  • 电子商务网站建设的规划和实施沈阳seo关键词
  • 建设个人你网站网址制作
  • 下列关于网站开发互联网广告推广是什么
  • 深圳网站建设 套餐上海网站推广广告
  • 阜阳网站推广seo服务是什么
  • 一个好的网站怎么建设自动点击器安卓
  • 网站日志分析有什么用app开发多少钱
  • 百度云服务器建设网站my77728域名查询
  • 乐清市住房和城乡规划建设局网站3d建模培训学校哪家好
  • 常州制作企业网站深圳网络营销外包公司推荐
  • 上海做淘宝网站seo内部优化方式包括
  • 10有免费建网站关键词三年级
  • 企业应如何进行网站建设西安百度竞价托管代运营
  • 网络工程设计项目方案设计优化关键词排名优化公司
  • 建设银行手机网站指数基金定投怎么买
  • 专门做心理测试的网站推广网络推广平台
  • 给企业做网站运营seo自学教程推荐
  • 手机网站怎么做淘宝客成都专门做网络推广的公司
  • excel表格做网站武汉seo收费
  • 济南区网站开发社群营销怎么做
  • 网站开发应如何入账培训心得体会怎么写
  • 做网站的销售为什么不建议去外包公司上班
  • 免费视频制作app老鬼seo
  • 网站错误代码 处理网站优化排名公司
  • 济南经三路专业做网站现在最好的免费的建站平台
  • 深圳做网站哪个好二级域名注册平台