3 sequence containers in STL
2015-09-19 04:16
471 查看
Vector:
vector is a dynamic array capable of growing as needed to contain its elements.
Support operator[],insert and removing elements from the end of the vector is generally fast.
vector.front(),vector.back();
vector.push_back(), vector.pop_back();
vector.capacity() is different from vector.size();
capacity usually allocate twice time of current size.
vector.reserve(); reserve the size of vector.
Deque (pronounced “deck”)
a double-ended queue class,implemented as a dynamic array that can grow from both ends.
This program produces the result:
8 9 10 0 1 2
List
a doubly linked list where each element in the container contains pointers that point at the next and previous elements in the list.
**Lists only provide access to the start and end of the list**there is no random access provided
The advantage of lists is that inserting elements into a list is very fast if you already know where you want to insert them. Generally iterators are used to walk through the list.
vector is a dynamic array capable of growing as needed to contain its elements.
Support operator[],insert and removing elements from the end of the vector is generally fast.
vector.front(),vector.back();
vector.push_back(), vector.pop_back();
vector.capacity() is different from vector.size();
capacity usually allocate twice time of current size.
vector.reserve(); reserve the size of vector.
Deque (pronounced “deck”)
a double-ended queue class,implemented as a dynamic array that can grow from both ends.
#include <iostream> #include <deque> int main() { using namespace std; deque<int> deq; for (int nCount=0; nCount < 3; nCount++) { deq.push_back(nCount); // insert at end of array deq.push_front(10 - nCount); // insert at front of array } for (int nIndex=0; nIndex < deq.size(); nIndex++) cout << deq[nIndex] << " "; cout << endl; }
This program produces the result:
8 9 10 0 1 2
List
a doubly linked list where each element in the container contains pointers that point at the next and previous elements in the list.
**Lists only provide access to the start and end of the list**there is no random access provided
The advantage of lists is that inserting elements into a list is very fast if you already know where you want to insert them. Generally iterators are used to walk through the list.
相关文章推荐
- OS每天15个注意点系列之UI-界面布局
- uva 540(Team Queue)
- easyUi 教程资料分享
- UITableView判断reloadData结束(iOS)
- hdoj 3836 Equivalent Sets【scc&&缩点】【求最少加多少条边使图强连通】
- String,StringBuffer,StringBuilder
- UITabBarController笔记(UITabBar/UITabBarButton)
- 从一个登陆页跳转到一个具有多个导航页面的工具栏控制器UITabbarController中
- Android中全局搜索(QuickSearchBox)详解
- 理解newid()和newsequentialid()
- easyUI——datagrid的动态显示和隐藏
- iOS UI基础-9.2 UITableView 简单微博列表
- iOS UIImageRenderingMode
- [DLX]HDOJ4069 Squiggly Sudoku
- 交互设计必懂--开发有价值的用户体验
- 增加用户体验的细节--三个按钮的交互设计思维
- 零基础掌握交互设计的重点笔记
- UI_UISegmentedControl
- Webserver issues | PHP manager for IIS
- UI_UISlider