vector list array deque
2016-06-02 09:18
387 查看
因此在实际使用时,如何选择这三个容器中哪一个,应根据你的需要而定,一般应遵循下面
的原则:
1、如果你需要高效的随即存取,而不在乎插入和删除的效率,使用vector
2、如果你需要大量的插入和删除,而不关心随即存取,则应使用list
3、如果你需要随即存取,而且关心两端数据的插入和删除,则应使用deque。
MSDN:
1. Introduction
The STL vector class is a template class of sequence containers that arrange elements of a given type in a linear arrangement and allow fast random access to any element.They should be the preferred container for a sequence when random-access performance is at a premium.
2. Compare
vectors allow constant time insertions and deletions at the end of the sequence.
Inserting or deleting elements in the middle of a vector requires linear time.
The performance of the deque Class container is superior with respect to insertions and deletions at the beginning and end of a sequence.
The list Class container is superior with respect to insertions and deletions at any location within a sequence.
3. Reallocation
Vector reallocation occurs when a member function must increase the sequence contained in the vector object beyond its current storage capacity.
Other insertions and erasures may alter various storage addresses within the sequence.
In all such cases, iterators or references that point at altered portions of the sequence become invalid.
If no reallocation happens, only iterators and references before the insertion/deletion point remain valid.
的原则:
1、如果你需要高效的随即存取,而不在乎插入和删除的效率,使用vector
2、如果你需要大量的插入和删除,而不关心随即存取,则应使用list
3、如果你需要随即存取,而且关心两端数据的插入和删除,则应使用deque。
MSDN:
1. Introduction
The STL vector class is a template class of sequence containers that arrange elements of a given type in a linear arrangement and allow fast random access to any element.They should be the preferred container for a sequence when random-access performance is at a premium.
2. Compare
vectors allow constant time insertions and deletions at the end of the sequence.
Inserting or deleting elements in the middle of a vector requires linear time.
The performance of the deque Class container is superior with respect to insertions and deletions at the beginning and end of a sequence.
The list Class container is superior with respect to insertions and deletions at any location within a sequence.
3. Reallocation
Vector reallocation occurs when a member function must increase the sequence contained in the vector object beyond its current storage capacity.
Other insertions and erasures may alter various storage addresses within the sequence.
In all such cases, iterators or references that point at altered portions of the sequence become invalid.
If no reallocation happens, only iterators and references before the insertion/deletion point remain valid.
相关文章推荐
- 08.LoT.UI 前后台通用框架分解系列之——多样的Tag选择器
- iOS 蓝牙使用小结 bluetooth
- POJ 2778 DNA Sequence (AC自动机,矩阵乘法)
- 07.LoT.UI 前后台通用框架分解系列之——强大的文本编辑器
- marquee---jsp中的滚动字幕标记
- Bluemix cf命令
- Bluemix 各个组件
- IBM bluemix Big Picture
- JavaSE_Java序列化和serialVersionUID
- HUE的简单介绍
- UItableViewCell一些实用细节与技巧
- UIDynamic 物理仿真
- uiimageView显示图片的中间部分
- UITableViewCell的一种得不到cell高度正确值问题的解决
- iOS-可拉伸放大的UITableView头部视图
- UITableView去除多余的分隔线
- UIPickerView选择视图
- UICollectionView详解
- UIView添加UITapGestureRecognizer和UITableView点击冲突
- APUE(3)---文件I/O (2)