#include <iostream>
#include <queue>
using namespace std;
class _Q_Node
{
public:
_Q_Node(int in_data=0)
{
next_node = nullptr;
data = in_data;
}
class _Q_Node* next_node;
int data;
};
class _Q_head
{
public:
_Q_head()
{
front = nullptr;
rear = nullptr;
size = 0;
}
_Q_Node* front;
_Q_Node* rear;
int size;
};
void push(_Q_head* in_q, int in_data)
{
_Q_Node* newnode = new _Q_Node(in_data);
if (in_q->size == 0)
{
in_q->front = newnode;
in_q->rear = newnode;
}
else
{
in_q->rear->next_node = newnode;
in_q->rear = newnode;
}
in_q->size++;
cout << newnode->data << "\n";
}
void pop(_Q_head* in_q)
{
if (in_q->size == 0) cout << "-1\n";
else
{
_Q_Node* deletenode = in_q->front;
cout << deletenode->data << "\n";
in_q->front = in_q->front->next_node;
delete deletenode;
in_q->size--;
}
}
void size(_Q_head* in_q)
{
cout<<in_q->size<<"\n";
}
void empty(_Q_head* in_q)
{
if (in_q->size == 0)
{
cout << "1\n";
}
else
{
cout << "0\n";
}
}
void front(_Q_head* in_q)
{
if (in_q->size == 0)
{
cout << "-1\n";
}
else
{
cout << in_q->front->data << "\n";
}
}
void back(_Q_head* in_q)
{
if (in_q->size == 0)
{
cout << "-1\n";
}
else
{
cout << in_q->rear->data << "\n";
}
}
int main()
{
_Q_head* q = new _Q_head;
int N;
cin >> N;
string cmd;
int num;
for (int i = 0; i < N; i++)
{
/**
* ToDo
* string을 통해 데이터를 받아 Queue로 처리하기
*/
cin >> cmd;
if (cmd == "push")
{
cin >> num;
push(q, num);
}
else if (cmd == "pop") { pop(q); }
else if (cmd == "size") { size(q); }
else if (cmd == "empty") { empty(q); }
else if (cmd == "front") { front(q); }
else if (cmd == "back") { back(q); }
}
delete q;
return 0;
}