//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. jndi 与 jdbc

    现在开发中经常用到数据库的两种配置1 jdbc2  jndi 一般开发环境都会使用jdbc环境,自己弄配置方便.但是测试和生产环境一般都使用jndi方式.原因有:1   使用jndi方式配置,数据库的 ...

  2. 如何通过fpmmm和zabbix来监控客户机上MariaDB数据库运行情况

    首先在客户机安装MariaDB和zabbix,参考上一篇 安装fpmmm的过程主要参考[1]. 安装fpmmm的依赖 shell> yum install php-cli php-process ...

  3. Discuz! X3.2重置管理员账号

    主要是使用了Tools急诊箱.先看一下Tools急诊箱的主要功能: 多种模式在线安装Discuz!,或者重装 重置管理员账号:将把您指定的会员设置为管理员 关闭功能:一键关闭/打开 [站点|插件]的操 ...

  4. Linux的一些简单命令(二)

    1.查看防火墙状态:service iptables status 2.开启防火墙:service iptables start 3.关闭防火墙:service iptables stop 4.创建目 ...

  5. sql第三天

    ->完整的select语句及执行顺序(必须记住) 5...select 5.2->distinct 7...top n [percent] 5.1->列名 聚合函数(1.2-> ...

  6. bzDemo

    <Public> <property name="Types"> <get/> </property> <method nam ...

  7. CentOS 6.5的安装详解

    CentOS 6.5的安装详解 主流: 目前的Linux操作系统主要应用于生产环境, 主流企业级Linux系统仍旧是RedHat或者CentOS 免费: RedHat 和CentOS差别不大,Cent ...

  8. C#中XmlSerializer的内存占用问题

    被XmlSerializer掉坑里了,爬了一晚上才出来. 本来实现一个功能,从数据库中查出一堆数据(比较多,几十万,不过,是分批查出来的),查出来的数据包含了一个XML字符串,代码中对其进行序列化,一 ...

  9. .net 获取类型的Type类型的几种方法

    一:使用Object基类的GetType()方法 Car car = new Car(); Type carType = car.GetType(); 二:使用typeof操作符 Type carTy ...

  10. Voting

    Voting time limit per test 1 second memory limit per test 256 megabytes input standard input output ...