VJ_Book shelf_deque

//
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,op,x;
    
    while( cin>>n )
    {
        deque<int> d;

        while( n-- )
        {
            cin>>op;
            if( op==1 )         { cin>>x; d.push_front(x); }
            else if( op==2 )    { cin>>x; d.push_back(x); }
            else if( op==3 )    { cout<<d.front()<<endl; d.pop_front(); }
            else if( op==4 )    { cout<<d.back()<<endl; d.pop_back(); }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/124632905
vj