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

网站开发公司的衡水做网站哪家好

网站开发公司的,衡水做网站哪家好,临清住房建设网站,企业网站优化问题一、list 插入和删除 函数原型#xff1a; push_back(elem);//在容器尾部加入一个元素 pop_back();//删除容器中最后一个元素 push_front(elem);//在容器开头插入一个元素 pop_front();//从容器开头移除第一个元素 insert(pos,elem);//在pos位置插elem元素的拷贝#xff0c…一、list 插入和删除 函数原型 push_back(elem);//在容器尾部加入一个元素 pop_back();//删除容器中最后一个元素 push_front(elem);//在容器开头插入一个元素 pop_front();//从容器开头移除第一个元素 insert(pos,elem);//在pos位置插elem元素的拷贝返回新数据的位置。 insert(pos,n,elem);//在pos位置插入n个elem数据无返回值。 insert(pos,beg,end);//在pos位置插入[beg,end)区间的数据无返回值。 clear();//移除容器的所有数据 erase(beg,end);//删除[beg,end)区间的数据返回下一个数据的位置。 erase(pos);//删除pos位置的数据返回下一个数据的位置。 remove(elem);//删除容器中所有与elem值匹配的元素。代码示例 #includeiostream using namespace std; #includelistvoid printList(const listint L) {for (listint::const_iterator it L.begin(); it ! L.end(); it){cout (*it) ;}cout endl; }void test() {listintL;//尾插L.push_back(10);L.push_back(20);L.push_back(30);//头插L.push_front(100);L.push_front(200);L.push_front(300);//300 200 100 10 20 30printList(L);//尾删 300 200 100 10 20L.pop_back();printList(L);//头删 200 100 10 20L.pop_front();printList(L);//insert插入 200 1000 100 10 20listint::iterator it L.begin();L.insert(it,1000);printList(L);//删除 200 100 10 20it L.begin();L.erase(it);printList(L);//移除L.push_back(10000);L.push_back(10000);L.push_back(10000);L.push_back(10000);printList(L);L.remove(10000);//删除所有printList(L);//清空L.clear();printList(L); }int main() {test();return 0; } 总结 尾插 --- push_back        尾删 --- pop_back 头插 --- push_front        头删 --- pop_front 插入 --- insert                 删除 --- erase 移除 --- remove              清空 --- clear   二、list 数据存取 函数原型 front(); //返回第一个元素。 back(); //返回最后一个元素。代码示例 #includeiostream using namespace std; #includelistvoid test() {listintL1;L1.push_back(10);L1.push_back(20);L1.push_back(30);L1.push_back(40);//L1[0] 不可以用[]访问list容器中的元素//L1.at(0) 不可以用at访问list容器中的元素//原因是list本质为链表不适用连续线性空间存储数据迭代器也是不支持随机访问的cout 第一个元素为 L1.front() endl;cout 最后一个元素为 L1.back() endl;//验证迭代器是不支持随机访问的listint::iterator it L1.begin();it;//it--,支持双向但写成itit1则出错不支持随机访问 }int main() {test();return 0; } 总结 list容器中不可以通过[]或者at方式访问数据 返回第一个元素 --- front 返回最后一个元素 --- back 三、list 反转和排序 函数原型 reverse(); //反转链表 sort(); //链表排序代码示例 #includeiostream using namespace std; #includelist #includealgorithmvoid printList(const listint L) {for (listint::const_iterator it L.begin(); it ! L.end(); it){cout (*it) ;}cout endl; }void test01() {//反转链表listintL1;L1.push_back(20);L1.push_back(10);L1.push_back(50);L1.push_back(40);L1.push_back(30);cout 反转前 endl;printList(L1);//反转L1.reverse();cout 反转后 endl;printList(L1); }bool myCompare(int v1,int v2) {//降序 就让第一个数 第二个数return v1 v2; }//排序链表 void test02() {listintL1;L1.push_back(20);L1.push_back(10);L1.push_back(50);L1.push_back(40);L1.push_back(30);//排序cout 排序前 endl;printList(L1);//所有不支持随机访问迭代器的容器不可以用标准算法// 不支持随机迭代器访问的容器内部会提供一些对应算法//sort(L1.begin(), L1.end());L1.sort();//默认排序规则 从小到大 升序cout 排序后 endl;printList(L1);L1.sort(myCompare);printList(L1); }int main() {//test01();test02();return 0; } 总结 反转 --- reverse 排序 --- sort 成员函数 四、排序案例 案例描述将Person自定义数据类型进行排序Person中属性有姓名、年龄、身高 排序规则按照年龄进行升序如果年龄相同按照身高进行降序 代码示例 #includeiostream using namespace std; #includelist #includestring//list容器 排序案例 class Person { public:Person(string name, int age, int height){this-m_Name name;this-m_Age age;this-m_Height height;}string m_Name;//姓名int m_Age; //年龄int m_Height;//身高 };//指定排序规则 bool comparePerson(Person p1, Person p2) {//按照年龄 升序if (p1.m_Age p2.m_Age){//年龄相同 按照身高降序return p1.m_Height p2.m_Height;}else{return p1.m_Age p2.m_Age;} }void test() {//创建容器listPersonL;//准备数据Person p1(刘备, 35, 175);Person p2(曹操, 45, 180);Person p3(孙权, 40, 170);Person p4(赵云, 25, 190);Person p5(张飞, 35, 160);Person p6(关羽, 35, 200);//插入数据L.push_back(p1);L.push_back(p2);L.push_back(p3);L.push_back(p4);L.push_back(p5);L.push_back(p6);for (listPerson49::iterator it L.begin(); it ! L.end(); it){cout 姓名 (*it).m_Name 年龄 (*it).m_Age 身高 (*it).m_Height endl;}//排序cout ---------------------------- endl;cout 排序后 endl;L.sort(comparePerson);for (listPerson::iterator it L.begin(); it ! L.end(); it){cout 姓名 (*it).m_Name 年龄 (*it).m_Age 身高 (*it).m_Height endl;} }int main() {test();return 0; } 总结 对于自定义数据类型必须要指定排序规则否则编译器不知道如何进行排序 高级排序只是在排序规则上再进行一次逻辑规则制定并不复杂
http://www.hkea.cn/news/14592272/

相关文章:

  • 手机网站实例用自己网站做邮箱域名
  • 长沙建网站设计公司用手机怎么做免费网站
  • 去哪个网站有客户找做标书的wordpress主题开发层级
  • 城乡建设门户网站怎么屏蔽优酷网站的广告
  • 旅游网站建设的经济评价seo查询网站
  • 站长平台怎么添加网站网站的创新点
  • 我们的爱情网站制作微信是哪个公司开发的
  • 商标设计logo网站wordpress 页面文章列表
  • 做山西杂粮的网站镇江建网站
  • 沈阳市网站建设公司网站建设烟台
  • 中企高呈网站建设为网站做seo需要什么
  • 做网站的视频教学网站备案号在哪里
  • 丹阳建站推广管理山西推广网站建设
  • 大悟网站开发小型教育网站的开发与建设
  • 北京高端网站建设服务宁波易通建设网站
  • 比价网站 源码wordpress 两栏
  • 山东网站制作应用wordpress安装 后
  • 武昌网站建设公司商城app开发模板
  • 标书制作公司网站有那些做自媒体短视频的网站
  • 知乎建站平台如何查询一个网站的空间大小
  • 免费建站好不好深圳网深圳网站开发公司
  • 包装网站建设客户管理软件有哪些
  • 县级网站建设企业网站 .net
  • 网站开发gxjzdrj网站关键字多少合适
  • 网站设计 专业网页设计网站怎么做特效
  • 个人建网站一般多少钱?湛江人做寄生虫网站
  • 珠海网站建设 amp 超凡科技空壳网站
  • 石林县工程建设个体交易网站免费金融发布网站模板
  • 百度验证网站的好处国外手做网站
  • 房屋租赁网站开发背景网站建设工作策划书