#include<deque>
#include<iostream>
using namespace std;
int main()
{
deque<int> d={1,2,3,4};
//访问首尾元素
cout<<d.front()<<" "<<d.back()<<endl;
cout<<*d.begin()<<" "<<*(d.end()-1)<<endl;
cout<<d[0]<<" "<<d[3]<<endl;
//添加头部元素
d.push_front(0);
//添加尾部元素
d.push_back(5);
for(auto &x: d) cout<<x<<" ";
cout<<endl;
//删除头部元素
d.pop_front();
//删除尾部元素
d.pop_back();
for(auto &x: d) cout<<x<<" ";
cout<<endl;
//使用emplace_front和emplace_back更加节省时间
d.emplace_front(0);
d.emplace_back(5);
for(auto &x: d) cout<<x<<" ";
return 0;
}