class MyQueue {
public:
/** Initialize your data structure here. */
stack<int> input;
stack<int> output;
MyQueue() {
}
/** Push element x to the back of queue. */
void push(int x) {
while(!output.empty()){
input.push(output.top());
output.pop();
}
output.push(x);
while(!input.empty()){
output.push(input.top());
input.pop();
}
}
/** Removes the element from in front of queue and returns that element. */
int pop() {
int ret = output.top();
output.pop();
return ret;
}
/** Get the front element. */
int peek() {
int ret = output.top();
return ret;
}
/** Returns whether the queue is empty. */
bool empty() {
return output.empty();
}
};
/**
* 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();
*/
今天知道的两个错误。
leetcode报错:reference binding to misaligned address 0xbebebebebebec0ba for type ‘int‘, which requir 4
在C++类中vector声明,报错 “expected parameter declarator”