STL学习记录(六):List
来源:互联网 发布:vb调用matlab工具箱 编辑:程序博客网 时间:2024/06/05 12:44
STL顺序容器List
List简介
List容器通过双向链表的形式来管理容器里的元素。这种方式表明他与Vector、Deque容器的不同。首先List不支持元素的随机访问,例如:你要访问第五个元素你必须先访问之前的四个。其次List的插入和移除操作更快。因为不需要移动元素它在任意位置的插入和移除操作的时间复杂度是常量。下面是List的常见操作:
迭代器
容量
直接访问
赋值类
修改类
特有的修改操作
代码示例:
#include <iostream>#include <list>#include <algorithm>#include <iterator>using namespace std;int main( ){ list<int> list_temp = {1, 2, 3, 3, 4, 6, 1, 1, 5}; list<int> list_reverse = list_temp; list_reverse.reverse(); cout<<"list_reverse: "; copy(list_reverse.cbegin( ),list_reverse.cend( ),ostream_iterator<int>(cout," ")); cout<<endl; list_temp.sort(); cout<<"list_sort: "; copy(list_temp.cbegin( ),list_temp.cend( ),ostream_iterator<int>(cout," ")); cout<<endl; list<int> list_merge = list_temp; list_temp.unique(); cout<<"list_unique: "; copy(list_temp.cbegin( ),list_temp.cend( ),ostream_iterator<int>(cout," ")); cout<<endl; list_merge.merge(list_temp); cout<<"list_merge: "; copy(list_merge.cbegin( ),list_merge.cend( ),ostream_iterator<int>(cout," ")); cout<<endl; return 0;}
运行结果:
list_reverse: 5 1 1 6 4 3 3 2 1
list_sort: 1 1 1 2 3 3 4 5 6
list_unique: 1 2 3 4 5 6
list_merge: 1 1 1 1 2 2 3 3 3 4 4 5 5 6 6
0 0
- STL学习记录(六):List
- STL学习记录(七):Forward List
- STL学习记录(一):STL简介
- STL学习(六)heap学习
- C++ STL源码学习(list篇)
- STL学习----入门(1)[list]
- C++STL学习(3)容器list
- STL 中 List 学习
- STL学习之list
- STL list学习摘记
- STL之list学习
- stl list学习
- list--初步学习STL
- STL中list学习
- STL学习之list
- STL学习之LIST
- STL学习之List
- 学习STL -- 列表list
- js运动-任意值添加运动
- jni使用注意
- POJ 3678 Katu Puzzle 2-SAT
- leetcode #5 Longest Palindromic Substring
- C学习笔记--指针(更新中)
- STL学习记录(六):List
- jquery用户自定义选择器及选择器高级用法实验
- 毕设(排课系统)笔记1---用户注册(二)
- JAVA程序设计基础教程 异常处理
- 输出一个学生的成绩数组,该数组中有五个学生的数据记录
- 使用TextView显示图像添加链接的方法
- SDKD 14级组队练习赛(一) J 递归打印图案
- 2015山东省赛B题-sdut3252---Lowest Unique Price
- Fedora13下真正能用的源(2015-5-16亲测)