class Queue {
stack<int> st[2];
int inidx, outidx;
void move(int from, int to) {
while (!st[from].empty()) {
st[to].push(st[from].top());
st[from].pop();
}
}
public:
Queue() {
inidx = 0;
outidx = 1;
}
// Push element x to the back of queue.
void push(int x) {
st[inidx].push(x);
}
// Removes the element from in front of queue.
void pop(void) {
if (st[outidx].empty() && !st[inidx].empty()) {
move(inidx, outidx);
}
if (!st[outidx].empty()) {
st[outidx].pop();
}
}
// Get the front element.
int peek(void) {
if (st[outidx].empty() && !st[inidx].empty()) {
move(inidx, outidx);
}
if (!st[outidx].empty()) {
return st[outidx].top();
} else {
return -1;
}
}
// Return whether the queue is empty.
bool empty(void) {
return st[inidx].empty() && st[outidx].empty();
}
};