目录
1.deque容器:
2.deque构造函数:
#include<iostream>
using namespace std;
#include<algorithm>
#include<deque>
void printDeque(const deque<int>d)
{
for (deque<int>::const_iterator it = d.begin(); it != d.end(); it++)
{
//*it = 100; 容器中的数据不可以修改了
cout << *it << " ";
}
cout << endl;
}
void test01()
{
deque<int>d1;
for (int i = 0; i < 9; i++)
{
d1.push_back(i);
}
printDeque(d1);
//区间赋值
cout << "区间赋值:"<<endl;
deque<int>d2(d1.begin(), d1.end());
printDeque(d2);
//括号赋值
deque<int>d3(10, 6);
cout << "括号赋值:" << endl;
printDeque(d3);
//拷贝
deque<int>d4(d3);
cout << "拷贝:" << endl;
printDeque(d4);
}
int main()
{
test01();
}
3.赋值操作:
#include<iostream>
using namespace std;
#include<algorithm>
#include<deque>
void printDeque(const deque<int>d)
{
for (deque<int>::const_iterator it = d.begin(); it != d.end(); it++)
{
//*it = 100; 容器中的数据不可以修改了
cout << *it << " ";
}
cout << endl;
}
void test01()
{
deque<int>d1;
for (int i = 0; i < 9; i++)
{
d1.push_back(i);
}
cout << "打印d1:" << endl;
printDeque(d1);
//等号赋值
deque<int>d2;
d2 = d1;
cout << "等号赋值:" << endl;
printDeque(d2);
//assign区间赋值
cout << "区间赋值:"<<endl;
deque<int>d3;
d3.assign(d3.begin(), d3.end());
printDeque(d3);
//n个elem
deque<int>d4;
cout << "n个elem:" << endl;
d4.assign(6, 6);
printDeque(d4);
}
int main()
{
test01();
}
4.大小操作:
#include<iostream>
using namespace std;
#include<algorithm>
#include<deque>
void printDeque(const deque<int>d)
{
for (deque<int>::const_iterator it = d.begin(); it != d.end(); it++)
{
//*it = 100; 容器中的数据不可以修改了
cout << *it << " ";
}
cout << endl;
}
void test01()
{
deque<int>d1;
for (int i = 0; i < 9; i++)
{
d1.push_back(i);
}
cout << "打印d1:" << endl;
printDeque(d1);
if (d1.empty())
{
cout << "d1为空" << endl;
}
else
{
cout << "d1不为空:" << endl;
cout << "d1的大小为:" << d1.size() << endl;
}
//重新指定大小
d1.resize(15);
printDeque(d1);
//d1.resize(15, 9);//指定其他空位填充9
//printDeque(d1);
d1.resize(5);//设置小,多的部分被删除
printDeque(d1);
}
int main()
{
test01();
}