/** Initialize your data structure here. */ queue<int> que; MyStack() {
} /** Push element x onto stack. */ voidpush(int x){ que.push(x); int len = que.size(); while(len > 1) { que.push(que.front()); //每次push一个元素都放到队尾 que.pop(); len--; } } /** Removes the element on top of the stack and returns that element. */ intpop(){ if(que.empty()) return-1; int temp = que.front(); que.pop(); return temp; } /** Get the top element. */ inttop(){ return que.front(); } /** Returns whether the stack is empty. */ boolempty(){ if(que.empty()) returntrue; else returnfalse; }