#include<bits/stdc++.h>
using namespace std;
int main()
{
int t, n, m, i = 1, x;
cin >> t;
while(t--)
{
string s;
deque<int>q;
cin >> n >> m;
cout << "Case " << i++ << ":\n";
while(m--)
{
cin >> s;
if(s == "pushLeft")
{
cin >> x;
if(q.size() == n)
cout << "The queue is full" << "\n";
else
{
q.push_front(x);
cout << "Pushed in left: " << x << "\n";
}
}
else if(s == "pushRight")
{
cin >> x;
if(q.size() == n)
cout << "The queue is full" << "\n";
else
{
q.push_back(x);
cout << "Pushed in right: " << x << "\n";
}
}
else if(s == "popLeft")
{
if(q.empty())
cout << "The queue is empty" << "\n";
else
{
int p = q.front();
q.pop_front();
cout << "Popped from left: " << p << "\n";
}
}
else if(s == "popRight")
{
if(q.empty())
cout << "The queue is empty" << "\n";
else
{
int p = q.back();
q.pop_back();
cout << "Popped from right: " << p << "\n";
}
}
}
}
return 0;
}
Comments
Post a Comment