//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. Oracle常用查询

    -- 创建Oracle sequence create sequence SEQ_XXHF minvalue 1 maxvalue 9999999999999999999999999999 start ...

  2. DotNetZip 压缩下载

    var fs = Response.OutputStream; using (ZipFile zip = new ZipFile(System.Text.Encoding.UTF8)) //编码是解决 ...

  3. JS中的call()和apply()方法理解和使用

    1.方法定义call方法: 语法:obj.method.call(thisObj[,arg1[, arg2[, [,.argN]]]]) 定义:调用对象(obj)的一个方法(method),以另一个对 ...

  4. gulp 安装步骤

    第一步:安装node 搭建node环境:进入官网 http://nodejs.org  ,然后点击的绿色的 install 按钮,下载完成后直接运行程序. 第二步:使用命令行 (1)输入指令:node ...

  5. 多表查询 INNER JOIN ON WHERE

    SELECT *FROM STUDENT_INFO siINNER JOIN CLASS_INFO ci on si.CLASS_INFO_ID = ci.ID INNER JOIN TEACHER_ ...

  6. iScroll 下 a 标签失效

    遇到个莫名其妙的问题,iScroll 下的 a 标签点击没有反应了,不管怎么调整 z-index 都无效果,很是无语. 查找半天后找到解决方法: $(function(){ new IScroll(' ...

  7. 【android错误】bitmap size exceeds 32bits

    使用图片缩放时遇到这么个问题: java.lang.IllegalArgumentException: bitmap size exceeds 32bits 后来一行行查代码,发现原来是 scale ...

  8. CodeForces 707A Brain's Photos

    简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...

  9. "The Application was unable to start correctly (0xc000007b). Click OK to close the application"

    我有时将MFC编译成64位并运行,就会报这个错误. 后来查找原因,就在于系统中使用了错误的dll.比如这个程序要使用64位的dll,而你拷贝进去的是同名的32位dll.解决方法就是放置正确的dll. ...

  10. crontab 添加sh文件定时

    (1)编写sh文件,比如/orcl/test/export.sh 编写crond文件 chmod 755 /orcl/test/*      //复制所有权限 [root@postest test]# ...