题目:
思路:
双向队列
deque的具体介绍
AC代码:
#include <iostream>
#include <cstdio>
#include <deque>
using namespace std;
deque <int> q;
int n;
int main()
{
cin>>n;for(int i=1;i<=n;i++){
int opt;cin>>opt;if(!opt){
int x;cin>>x;q.push_front(x);}else{
if((opt==1)&&(!q.empty())) q.pop_front();else{
if(opt==2){
int x;cin>>x;q.push_back(x);}else{
if((opt==3)&&(!q.empty())) q.pop_back();} }}}for(int i=0;i<(int)q.size();i++) cout<<q[i]<<" ";cout<<endl;return 0;
}