deque
双端数组。可以对头尾进行插入和删除操作
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
void printdeque(const deque<int> &d)
{
for (deque<int>::const_iterator it = d.begin(); it != d.end(); it++)
cout << *it << " ";
cout << endl;
}
int main()
{
deque<int> d1;
for (size_t i = 0; i < 10; i++)
{
d1.push_front(i);//头插
d1.push_back(i + 1);//尾插
}
sort(d1.begin(), d1.end());//升序
printdeque(d1);
if (d1.empty())
cout << "v1为空" << endl;
else
cout << "v1的大小为:" << d1.size() << endl;
printdeque(d1);
d1.pop_back();//删除最后一个元素
printdeque(d1);
d1.insert(d1.begin(), -1);//指定位置插入
printdeque(d1);
//d1.erase(d1.begin());//删第一个
d1.erase(d1.begin() + 4, d1.end());//区间删除
printdeque(d1);
system("pause");
return 0;
}
标签:deque,begin,const,--,C++,end,include,d1
From: https://blog.51cto.com/u_16071993/6669988