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依赖注入使用详解 ...
随机推荐
- [Q]手动加载菜单方法
一般情况下,安装程序会自动安装依云软件菜单,但可能由于某些原因未能自动安装的话,您可以手动加载菜单,步骤如下: 在AoutCAD命令行输入"CUILOAD",会弹出"加载 ...
- Python基础知识学习_Day7
一.Subprocess模块 1常用方法 执行命令,返回命令执行状态,0 or非0 >>> retcode = subprocess.call(["ls", &q ...
- DevExpress的SpinEdit控件无法输入数字的问题
今天在发布程序后突然发现了这个问题,刚开始很莫名其妙的,因为在调试时从来没碰到过.然后经过测试发现,这个问题的原因和输入法有很大关系: 当你的输入法是中文状态时,是无法向框中输入数字的,此时只能点击上 ...
- Redis 数据序列化方法 serialize, msgpack, json, hprose 比较
最近弄 Redis ,涉及数据序列化存储的问题,对比了:JSON, Serialize, Msgpack, Hprose 四种方式 1. 对序列化后的字符串长度对比: 测试代码: $arr = [0, ...
- JDK各版本新增的主要特性
JDK1.5新特性: 1.自动装箱与拆箱: 2.枚举 3.静态导入,如:import staticjava.lang.System.out 4.可变参数(Varargs) 5.内省(Introspec ...
- 怎么 得到 DBGrid选中行的数据
转自:https://zhidao.baidu.com/question/1694035814426308148.html 一般是你鼠标点到哪一行,其DataSet的指针就指到了什么位置你可以直接通过 ...
- iOS跳转系统设置界面
iOS开发之如何跳到系统设置里的各种设置界面:http://www.superqq.com/blog/2015/12/01/jump-setting-per-page/ iOS:你App的设置做对了吗 ...
- 扯蛋css
使网页旋转代码: javascript:window.i=1;setInterval(function(){i++;document.body.style.cssText+="-webkit ...
- SQL中游标的使用--遍历数据逐行更新或删除:相当于for循环
--------------------------------------例子1 单纯的游标-------------------------------- create TABLE Table1 ...
- 常见dos命令
打开控制面板:win+r control 服务: win+r services.msc