//List容器
//List本质是一个双向链表 //构造函数
list<int>c0; //空链表
list<int>c1(3); //建一个含三个默认值是0的元素链表
list<int>c2(5,2); //含5个元素,值都是2
list<int>c4(c2); //复制链表
list<int>c5(c1.begin(), c1.end()); //c5包含c1的一个区域元素 //成员函数
c.begin() //返回链表第一个元素的迭代器
c.end() //返回指向链表最后一个元素之后的迭代器 c.rbegin() //返回逆向链表的第一个元素,即c链表的最后一个数据
c.rend() //返回逆向链表的最后一个元素下一个位置,即c链表的第一个数据再往前的位置
//example
list<int>l1 = {1,2,3,4};
for (list<int>::reverse_iterator it = l1.rbegin(); it != l1.rend(); it++)
cout << *it << endl; operator= //重载赋值元素符 c.assign(n, num) //将n个num拷贝赋值给链表c
c.assign(beg, end) //将[beg, end]区间的元素拷贝赋值给链表c
//Example
list<int>l1 ;
l1.assign(2, 10);
for (list<int>::iterator it = l1.begin(); it != l1.end(); it++)
cout << *it << endl;
l1.clear();
int a[5] = { 1, 2, 3, 4, 5 };
l1.assign(a, a + 5);
for (list<int>::iterator it = l1.begin(); it != l1.end(); it++)
cout << *it << endl; c,front() //返回第一个元素
c.back() //返回最后一个元素 c.empty() //判空 c.size() //返回元素个数 c.max_size() //返回可能容纳最大元素数量 c.clear() //清除c中所有元素 c.insert(pos,num) //在pos位置插入元素num。
c.insert(pos,n,num) //在pos位置插入n个元素num。
c.insert(pos,beg,end) //在pos位置插入区间为[beg,end)的元素。 c.erase(pos) //删除pos位置元素 c.push_back(num) //在末尾增加一个元素。
c.pop_back() //删除末尾的元素。
c.push_front(num) //在开始位置增加一个元素。
c.pop_front() //删除第一个元素。 c.resize(n) //重新定义链表长度,超出原始长度部分用0代替,小于原始部分删除
c.resize(n, num) //重新定义链表长度,超出原始长度部分用num代替,小于原始部分删除 c1.swap(c2); //将c1和c2交换。
swap(c1,c2); //同上。 c1.merge(c2) //合并2个有序的链表并使之有序,重新放到c1里,释放c2。
c1.merge(c2,comp) //合并2个有序的链表并使之按照自定义规则排序之后重新放到c1中,释放c2,comp为比较函数,默认合成为升序
//comp是一个函数名称
//要依据实际情况设计compare
bool compare(int n1, int n2)
{
return n1 > n2;
} int main()
{
list<int>l1{ 4,2,1 }, l2{ 6,5,3 };
list<int>::iterator it;
l1.merge(l2,compare);
for (it = l1.begin(); it != l1.end(); it++)
cout << *it << endl; return 0;
} c1.splice(c1.beg, c2) //将c2连接在c1的beg位置,释放c2
//Example
list<int>l1{ 1, 2, 3 }, l2{ 4, 5, 6 };
l1.splice(l1.begin(), l2);
list<int>::iterator it;
for (it = l1.begin(); it != l1.end(); it++)
cout << *it << endl; c1.splice(c1.beg, c2, c2.beg) //将c2的beg位置的元素连接到c1的beg位置,并且在c2中释放掉beg位置的元素 c1.remove(num) //删除链表中匹配num的元素。 c1.remove_if(comp) //删除条件满足的元素,参数为自定义的回调函数。
//Example
bool compare(int n)
{
return n < 2;
}
int main()
{
list<int>l1{ 1, 2, 3 }, l2{ 4, 5, 6 };
list<int>::iterator it;
l1.remove_if(compare);
for (it = l1.begin(); it != l1.end(); it++)
cout << *it << endl; system("pause");
return 0;
} c1.reverse() //反转链表 c1.unique() //删除相同的元素,只剩下一个 c.sort() //将链表排序,默认升序
c.sort(comp) //自定义回调函数实现自定义排序

  

List container的更多相关文章

  1. 在docker中运行ASP.NET Core Web API应用程序(附AWS Windows Server 2016 widt Container实战案例)

    环境准备 1.亚马逊EC2 Windows Server 2016 with Container 2.Visual Studio 2015 Enterprise(Profresianal要装Updat ...

  2. .Container与.container_fluid区别

    .Container与.container_fluid是bootstrap中的两种不同类型的外层容器,两者的区别是:.container 类用于固定宽度并支持响应式布局的容器..container-f ...

  3. View and Data API Tips: Constrain Viewer Within a div Container

    By Daniel Du When working with View and Data API, you probably want to contain viewer into a <div ...

  4. [LeetCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  5. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

  6. Docker - command in docker container

    1.查看Container 里面运行的进程 在运行容器以后,可以查看里面的进程: docker top <container_id> or <container_name> 2 ...

  7. 【leetcode】Container With Most Water

    题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...

  8. 7 Container With Most Water_Leetcode

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  9. [LintCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  10. ASP.NET MVC中使用Unity Ioc Container

    写在前面 安装Unity 添加服务层 IArticleRepository类型映射 服务注入到控制器 Global.asax初始化 后记 关于Unity的使用可以参照<Unity依赖注入使用详解 ...

随机推荐

  1. netty高级篇(3)-HTTP协议开发

    一.HTTP协议简介 应用层协议http,发展至今已经是http2.0了,拥有以下特点: (1) CS模式的协议 (2) 简单 - 只需要服务URL,携带必要的请求参数或者消息体 (3) 灵活 - 任 ...

  2. ubuntu 使用apt-get install 安装php5.6--php7

    使用ppa增加源:$ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:ondrej/php ...

  3. Oracle 收集统计数据

    查看最新用户表统计信息 select owner,table_name,last_analyzed from dba_tables where owner not like '%SYS%' order ...

  4. 敏捷开发(五)- 框架SCRUM内容

    本文主要是为了检测你对SCRUM的了解和使用程度,通过本文你可以检测一下     1.你们的SCRUM项目中各个角色是否合格,    2.SCRUM上面需要的会议是否有遗留,会议过程是否正确    3 ...

  5. USACO 3.2 Magic Squares

    Magic SquaresIOI'96 Following the success of the magic cube, Mr. Rubik invented its planar version, ...

  6. 【3】Chrome 的一些常用操作

    记录一些 Chrome 的常用操作 1. 让页面可以编辑 1). 在 控制台 输入 document.designMode = 'on';  链接地址>>

  7. ElasticSearch(7)-排序

    引用自ElaticSearch权威指南 一.排序 相关性排序 默认情况下,结果集会按照相关性进行排序 -- 相关性越高,排名越靠前. 这一章我们会讲述相关性是什么以及它是如何计算的. 在此之前,我们先 ...

  8. Uploadify 上传后的文件删除,上传队列无法更新问题

    1. 定义一个上传限制数量 var uploadLimit = 3; 2. 点击页面的删除图片成功后,将uploadLimit++操作 3. 通过uploadify的settings方式重置上传限制数 ...

  9. MessageBox.Show()时MessageBoxIcon的显示

    MessageBox.Show()方法,有个参数是MessageBoxIcon,这个是通过图标来表明提示信息的类型,比如一般.警告.错误等 MessageBoxIcon是一个枚举 所有成员如图: 示例 ...

  10. VMMap(查看内存工具)

    来源: http://www.cnblogs.com/georgepei/archive/2012/03/07/2383445.html http://www.cnblogs.com/georgepe ...