题目请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作push、pop、peek、empty实现MyQueue类void push(int x)将元素 x 推到队列的末尾int pop()从队列的开头移除并返回元素int peek()返回队列开头的元素boolean empty()如果队列为空返回true否则返回false说明你 只能 使用标准的栈操作 —— 也就是只有push to top,peek/pop from top,size, 和is empty操作是合法的。你所使用的语言也许不支持栈。你可以使用 list 或者 deque双端队列来模拟一个栈只要是标准的栈操作即可。本题主要先用来熟悉这些push、pop、top等操作的用法用栈实现队列还是好理解的。class MyQueue { public: stackint stIn; stackint stOut; MyQueue() { } void push(int x) { stIn.push(x); } int pop() { if (stOut.empty()) { while (!stIn.empty()) { stOut.push(stIn.top()); stIn.pop(); } } int result stOut.top(); stOut.pop(); return result; } int peek() { int res this-pop();//使用已有的pop函数 stOut.push(res); //出栈再入栈 return res; } bool empty() { if (stOut.empty() stIn.empty()) { return true; } return false; } }; /** * Your MyQueue object will be instantiated and called as such: * MyQueue* obj new MyQueue(); * obj-push(x); * int param_2 obj-pop(); * int param_3 obj-peek(); * bool param_4 obj-empty(); */