C++:
class CQueue {
public:
std::stack<int> headStack;
std::stack<int> tailStack;
public:
CQueue() {
}
void appendTail(int value) {
this -> tailStack.push(value);
}
int deleteHead() {
if ( this -> headStack.empty() ) {
while ( !( this -> tailStack.empty() ) ) {
this -> headStack.push( this -> tailStack.top() );
this -> tailStack.pop();
}
}
if ( !( this -> headStack.empty() ) ) {
int returnedValue = this -> headStack.top();
this -> headStack.pop();
return returnedValue;
}
return -1;
}
};
/**
* Your CQueue object will be instantiated and called as such:
* CQueue* obj = new CQueue();
* obj->appendTail(value);
* int param_2 = obj->deleteHead();
*/