/** Removes the element on top of the stack and returns that element. */ intpop(){ int result=0; if(!stack1.empty()){ result=stack1.front(); stack1.pop(); }else{ result=stack2.front(); stack2.pop(); } return result; }
/** Get the top element. */ inttop(){ if(!stack1.empty()){ return stack1.front(); } return stack2.front(); }
/** Returns whether the stack is empty. */ boolempty(){ if(stack1.empty()&&stack2.empty()){ returntrue; } returnfalse; } };