C++ List的用法(整理)
来源:互联网 发布:上海网络推广铭心 编辑:程序博客网 时间:2024/06/05 03:19
Lists将元素按顺序储存在链表中. 与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比较慢.
assign() 给list赋值
back() 返回最后一个元素
begin() 返回指向第一个元素的迭代器
clear() 删除所有元素
empty() 如果list是空的则返回true
end() 返回末尾的迭代器
erase() 删除一个元素
front() 返回第一个元素
get_allocator() 返回list的配置器
insert() 插入一个元素到list中
max_size() 返回list能容纳的最大元素数量
merge() 合并两个list
pop_back() 删除最后一个元素
pop_front() 删除第一个元素
push_back() 在list的末尾添加一个元素
push_front() 在list的头部添加一个元素
rbegin() 返回指向第一个元素的逆向迭代器
remove() 从list删除元素
remove_if() 按指定条件删除元素
rend() 指向list末尾的逆向迭代器
resize() 改变list的大小
reverse() 把list的元素倒转
size() 返回list中的元素个数
sort() 给list排序
splice() 合并两个list
swap() 交换两个list
unique() 删除list中重复的元素
实例一:
结果:
listOne.begin()--- listOne.end():
1 2 3 4
listOne.rbegin()---listOne.rend():
4 3 2 1
Sum=10
------------------
listTwo.begin()---listTwo.end():
B A x y
The maximum element in listTwo is: y
Press any key to continue
实例二:
结果:
The contents of list1 :
The contents of list2 : 6 6 6 6 6 6 6 6 6 6
The contents of list3 : 6 6 6 6 6 6 6 6 6
list1.push_back(2) and list1.push_back(4):
The contents of list1 : 2 4
list1.push_front(5) and list1.push_front(7):
The contents of list1 : 7 5 2 4
list1.insert(list1.begin()+1,3,9):
The contents of list1 : 7 9 9 9 5 2 4
list1.front()=7
list1.back()=4
list1.pop_front() and list1.pop_back():
The contents of list1 : 9 9 9 5 2
list1.erase(++list1.begin()):
The contents of list1 : 9 9 5 2
list2.assign(8,1):
The contents of list2 : 1 1 1 1 1 1 1 1
list1.max_size(): 1073741823
list1.size(): 4
list1.empty(): 0
The contents of list1 : 9 9 5 2
The contents of list3 : 6 6 6 6 6 6 6 6 6
list1>list3: 1
list1<list3: 0
The contents of list1 : 2 5 9 9
The contents of list1 : 2 6 6 6 6 6 6 6 6 6 5 9 9
The contents of list3 :
Press any key to continue
- C++ List的用法(整理)
- C++ List的用法(整理)
- C++ List的用法(整理)
- C++ List的用法(整理)
- C++ List的用法(整理)
- C++ List的用法(整理)
- C++ List的用法(整理)
- C++ List的用法(整理)
- C++list的用法
- c++ list的用法(整理)
- c++中容器list的用法整理
- [C#]list的removeall用法
- 【C++】容器list的用法
- C++中list用法整理
- [转][整理]extern "C"的用法解析
- c#List 用法详解
- C#List<T>用法
- C#List<T>用法
- Python正则表达式
- (lintcode)第16题 带重复元素的排列
- MySQL笔记【持续更新……】
- Java中==和equals的区别
- 树形依赖动态规划
- C++ List的用法(整理)
- 领域驱动设计,读书笔记:4 绑定模型和实现
- Android源码硬件加速简析
- Leetcode659——Split Array into Consecutive Subsequences
- 学习笔记-IO流-系统输出
- 【美团】最大矩形面积(分治法)
- 模式识别绪论
- 操作mysql数据库,出现中文乱码如何解决?
- linux僵尸进程和孤儿进程