//#include "stdafx.h"
//#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
deque<int> d;
void show(deque<int> &tem_d)
{
for (deque<int>::iterator it = tem_d.begin(); it != tem_d.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
int main()
{
d.push_back(1);
d.push_back(3);
d.push_front(-1);
d.push_front(-3);
show(d);
deque<int>::iterator it = find(d.begin(), d.end(), -1); //查找指定元素的下标
if (it != d.end())
cout << "元素-1的下标为:" << distance(d.begin(), it) << endl;
else
cout << "没有元素-1" << endl;
cout << "头部元素:" << d.front() << endl;
cout << "尾部元素:" << d.back() << endl;
cout << "修改头部元素:" << endl;
d.front() = -11;
show(d);
cout << "修改尾部元素:" << endl;
d.back() = 33;
show(d);
cout << "删除头部元素:" << endl;
d.pop_front();
show(d);
cout << "删除尾部元素:" << endl;
d.pop_back();
show(d);
cout << endl;
system("pause");
return 0;
}
deque容器的最最最简单操作
最新推荐文章于 2021-12-18 23:20:55 发布