牛客-用兩個棧實現隊列
#include <stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <string.h>
#include <string>
#include <cstring>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
class Solution
{
public:
void push(int node) {
stack1.push(node);
}
int pop() {
if (!stack2.empty()) {
int top = stack2.top();
stack2.pop();
return top;
} else {
while (!stack1.empty()) {
int top = stack1.top();
stack2.push(top);
stack1.pop();
}
int top = stack2.top();
stack2.pop();
return top;
}
}
private:
stack<int> stack1;
stack<int> stack2;
};