classMyQueue { public: int stk[100010]; int tmp_stk[100010]; int tt; int tmp_tt;
/** Initialize your data structure here. */ MyQueue() { tt = 0; tmp_tt = 0; }
/** Push element x to the back of queue. */ voidpush(int x){ // 0不用,直接用1 stk[++ tt] = x; }
/** Removes the element from in front of queue and returns that element. */ intpop(){ // stk只留下1个,其它全部移到辅助栈tmp_stk里去 while(tt > 1){ // tmp_stk入栈,stk出栈 tmp_stk[++ tmp_tt] = stk[tt --]; }
/** Returns whether the queue is empty. */ boolempty(){ return !tt; } };
/** * Your MyQueue object will be instantiated and called as such: * MyQueue obj = MyQueue(); * obj.push(x); * int param_2 = obj.pop(); * int param_3 = obj.peek(); * bool param_4 = obj.empty(); */