c++的deque容器的基本操作

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
using namespace std;
void printDeque(const deque& d)
{
	for (deque::const_iterator it = d.begin(); it != d.end(); it++)
	{
		cout << *it << " ";
	}
	cout << endl;
}
void test01()
{
	int arr[] = { 1,2,3,4 };
	deque d(arr, arr + sizeof(arr) / sizeof(int));
	printDeque(d);
	dequed1(10, 6);
	printDeque(d1);
}
//赋值操作
void test02()
{
	int arr[] = { 1,2,3,4 };
	deque d(arr, arr + sizeof(arr) / sizeof(int));
	deque d1(d.begin(), d.end());
	printDeque(d1);
	d1.push_back(100);
	printDeque(d1);
	d.swap(d1);
	printDeque(d);
	printDeque(d1);
}
//大小
void test03()
{
	dequed;
	d.resize(10, 6);
	printDeque(d);
}
//插入
void test04()
{
	dequed;
	d.push_back(10);
	d.push_back(20);
	d.push_back(30);
	d.insert(d.begin() + 1, 100);
	d.insert(d.begin()+1, 2, 3);
	printDeque(d);
	dequed2;
	d2.push_back(1000);
	d2.push_back(2000);
	d2.insert(d2.begin(), d.begin(), d.end());
	printDeque(d2);
	deque::iterator it=d2.erase(d2.begin() + 1, d2.end() - 1);//返回d2.end()-1的地址
	cout << *it << endl;
	printDeque(d2);
}
int main()
{
	test04();
	system("pause");
	return EXIT_SUCCESS;
}

你可能感兴趣的:(c++,开发语言)