List的使用方法
来源:互联网 发布:抚顺市政府采购网域名 编辑:程序博客网 时间:2024/05/21 00:53
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
- Virtual List的使用方法
- List的Contains使用方法
- Virtual List的使用方法
- Virtual List的使用方法
- 简单的list使用方法
- List的使用方法
- C++的list使用方法
- List Lambda的使用方法
- Mark: list的使用方法
- list容器的使用方法
- List的使用方法
- 【C++】list的使用方法
- VC++中list::list的使用方法总结
- VC++中list::list的使用方法总结
- VC++中list::list的使用方法总结
- VC++中list::list的使用方法总结
- VC++中list::list的使用方法总结
- VC++中list::list的使用方法总结
- 深入源码理解-java动态代理
- git(四)-分支进阶与版本回退
- 7月英语总结博客
- Android中读取assets目录下的文件详细介绍
- BottomSheetDialog(design包的一个组件)
- List的使用方法
- 中介者模式--充当联合国的角色
- webview遇到的坑
- 网络爬虫原理
- 蓝牙4.0BLE抓包(三) – 扫描请求和扫描响应
- 图的邻接矩阵存储之C++封装
- Vscode
- MIME对应关系
- 网络爬虫之java基础(Ⅰ) 标签: java网络爬虫