标签:
deque采用模板类实现,deque对象的默认构造形式:deque<T> deq;
deque <int> deqInt; //一个存放int的deque容器。
deque <float> deq Float; //一个存放float的deque容器。
3.deque对象的带参数构造
#include<iostream> using namespace std; #include <deque> void objPlay3() { deque<int> deqIntA; deqIntA.push_back(1); deqIntA.push_back(3); deqIntA.push_back(5); deqIntA.push_back(7); deqIntA.push_back(9); deque<int> deqIntB(deqIntA.begin(), deqIntA.end()); //1 3 5 7 9 deque<int> deqIntC(5, 8); //8 8 8 8 8 deque<int> deqIntD(deqIntA); //1 3 5 7 9 } int main() { objPlay3(); return 0; }
void objPlay4() { deque<int> deqIntA, deqIntB, deqIntC, deqIntD; deqIntA.push_back(1); deqIntA.push_back(3); deqIntA.push_back(5); deqIntA.push_back(7); deqIntA.push_back(9); deqIntB.assign(deqIntA.begin(), deqIntA.end()); // 1 3 5 7 9 deqIntC.assign(5, 8); //8 8 8 8 8 deqIntD = deqIntA; //1 3 5 7 9 deqIntC.swap(deqIntD); //C 和 D互换 }
5.deque的大小
void objPlay5()
{
deque<int> deqIntA;
deqIntA.push_back(1);
deqIntA.push_back(3);
deqIntA.push_back(5);
int iSize = deqIntA.size(); //3
if (!deqIntA.empty())
{
deqIntA.resize(5); //1 3 5 0 0
deqIntA.resize(7, 1); //1 3 5 0 0 1 1
deqIntA.resize(2); //1 3
}
}
6.deque末尾的添加移除操作
8.deque的插入
标签:
原文地址:http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_stl_003.html