我把他全部丢进第二个stack
然后他就会倒过来
然后把上面的丢掉
然后再塞回去
感觉好麻烦喔= =
然后那个MyQueue()是在干嘛的阿
我不知道他是什么
class MyQueue {
public:
vector<int> stack1;
vector<int> stack2;
MyQueue()
{
vector<int> stack1;
vector<int> stack2;
}
void push(int x)
{
stack1.push_back(x);
}
int pop()
{
while(!stack1.empty())
{
stack2.push_back(stack1.back());
stack1.pop_back();
}
int k = stack2.back();
stack2.pop_back();
while(!stack2.empty())
{
stack1.push_back(stack2.back());
stack2.pop_back();
}
return k;
}
int peek()
{
while(!stack1.empty())
{
stack2.push_back(stack1.back());
stack1.pop_back();
}
int k = stack2.back();
while(!stack2.empty())
{
stack1.push_back(stack2.back());
stack2.pop_back();
}
return k;
}
bool empty()
{
return stack1.empty();
}
};