deque的使用
来源:互联网 发布:linux ulimit 编辑:程序博客网 时间:2024/06/04 19:44
#include<iostream>
#include<deque>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
deque<string> coll;
coll.assign(3, string("string"));
coll.push_back("last string");
coll.push_front("first string");
copy(coll.begin(), coll.end(),
ostream_iterator<string>(cout, "\n"));
coll.pop_front();
coll.pop_back();
for (int i = 1; i < coll.size(); i++)
{
coll[i] = "another " + coll[i];
}
coll.resize(4, "resized string");
copy(coll.begin(), coll.end(), ostream_iterator<string>(cout, "\n"));
getchar();
getchar();
#include<deque>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
deque<string> coll;
coll.assign(3, string("string"));
coll.push_back("last string");
coll.push_front("first string");
copy(coll.begin(), coll.end(),
ostream_iterator<string>(cout, "\n"));
coll.pop_front();
coll.pop_back();
for (int i = 1; i < coll.size(); i++)
{
coll[i] = "another " + coll[i];
}
coll.resize(4, "resized string");
copy(coll.begin(), coll.end(), ostream_iterator<string>(cout, "\n"));
getchar();
getchar();
}
以下为输出的结果:
first string
string
string
string
last string
string
another string
another string
resized string
deque与vector相比之下有几点不同之处
1.deque能够快速的在首部和尾部安插元素,这些操作都分摊在常熟时间内。
2.存取元素的时候deque的内部结构会多一个间接地过程,所以元素的存取和迭代器的动作会稍微慢一些
3.迭代器需要在不同的块之间跳转,所以必须是特殊的智能指针,非一般指针。
4.在对内存块有所限制的系统中,deque可以内含更多的元素,因为他不止一块内存,因为deque的max_size可能更大。
5.当deque的内存块不在使用的时候,会被释放,deque的内存大小是可缩减的,不过实际情况由版本决定。
6.迭代器属于随机存取迭代器。
在以下的情况下使用deque
1.你需要在两端安插或者移除元素。
2.无需引用容器内的元素。
3.要求容器释放不再使用的元素。
0 0
- STL deque的使用
- deque的使用
- C++deque的使用
- STL 中 deque 的使用
- deque使用
- Deque使用
- STL中deque的使用例子
- vector, list, deque的使用区别
- vector 、deque、 list的使用总结
- 深入分析C++中deque的使用
- deque和map的使用(poj3074)
- 深入分析C++中deque的使用
- c++ deque使用
- STL deque简单使用
- stl deque使用详解
- STL容器deque使用
- std::vector,std::deque,std::list的区别的使用
- stl中vector,list,deque的使用准则
- HDU 2086
- XP系统罕见操作技巧
- 求1+2+3+...+n,要求不能使用乘除法,for,while,if,else,switch,case等关键字以及条件判断语句
- 2014巴西世界杯尘埃落定
- 深入浅出桥梁模式
- deque的使用
- 2014大众点评Hackathon参赛感想
- Spring mvc 中使用 kaptcha 验证码
- 应用开发博客收集
- C_C++变量命名规则
- 关于磁盘管理小结【收集中】
- 排序算法(1)-插入,选择,冒泡
- HDU 2040
- HDUJ 1050 Moving Tables 贪心