List container
//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的更多相关文章
- 在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 ...
- .Container与.container_fluid区别
.Container与.container_fluid是bootstrap中的两种不同类型的外层容器,两者的区别是:.container 类用于固定宽度并支持响应式布局的容器..container-f ...
- 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 ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- Docker - command in docker container
1.查看Container 里面运行的进程 在运行容器以后,可以查看里面的进程: docker top <container_id> or <container_name> 2 ...
- 【leetcode】Container With Most Water
题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- 7 Container With Most Water_Leetcode
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- [LintCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- ASP.NET MVC中使用Unity Ioc Container
写在前面 安装Unity 添加服务层 IArticleRepository类型映射 服务注入到控制器 Global.asax初始化 后记 关于Unity的使用可以参照<Unity依赖注入使用详解 ...
随机推荐
- hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...
- http://www.spasvo.com/ceshi/open/kyxncsgj/Jmeter/
http://www.spasvo.com/ceshi/open/kyxncsgj/Jmeter/
- 使用 FormsAuthentication 来进行登录验证
1.在web.config文件中,<system.web>/<authentication>配置节用于对验证进行配置.为<authentication>节点提供mo ...
- [ An Ac a Day ^_^ ][kuangbin带你飞]专题六 最小生成树 POJ 2031 Building a Space Station
最小生成树模板题 注意最后输出用%f (从C99开始%f已经不能用于输出double 即 输入用%lf 输出用%f) #include<cstdio> #include<algori ...
- Cracking the Coding Interview 第一章
第一章:数组与字符串 1 数组与字符串 请实现一个算法,确定一个字符串的所有字符是否全都不同.这里我们要求不允许使用额外的存储结构. 给定一个string iniString,请返回一个bool值,T ...
- 排序 之 快排、归并、插入 - <时间复杂度>----掌握思想和过程
俗话说:天下武功无坚不破,唯快不破.对于算法当然也是要使用时间最短.占用空间最小的算法来实现了. 注意:我代码里面打的备注仅供参考,建议不要背模板(因为没有固定的模板),可以写一个数列按着代码跑两圈或 ...
- [DP优化方法之虚树]
首先我们看一篇文章 转自xyz: 给出一棵树. 每次询问选择一些点,求一些东西.这些东西的特点是,许多未选择的点可以通过某种方式剔除而不影响最终结果. 于是就有了建虚树这个技巧..... 我们可以用l ...
- Lua: 给 Redis 用户的入门指导
转自:http://www.oschina.net/translate/intro-to-lua-for-redis-programmers 可能你已经听说过Redis 中嵌入了脚本语言,但是你还没有 ...
- Ansible hostvars
1. inventory hosts file 中的server 变量会覆盖group变量. hostvars: { "iaas_name": "test", ...
- lucene 索引删除
1.IndexWriter和IndexReader都有删除索引的方法:deleteDocuments(); 不建议使用IndexReader删除索引:使用IndexReader进行删除时,必须关闭所有 ...