#include <iostream>
#include <stack>
using namespace std;
class Queue {
private:
stack<int> s1;
stack<int> s2;
public:
//判断队空
bool IsEmpty() {
return s1.empty() && s2.empty();
}
//入队
void EnQueue(int node) {
s1.push(node);
}
//出队
int DeQueue() {
if (IsEmpty()) {
cout << "队空!" << endl;
exit(1);
}
if (s2.empty()) {
while (!s1.empty()) {
s2.push(s1.top());
s1.pop();
}
}
int node = s2.top();
s2.pop();
return node;
}
};
int main() {
//TODO 自己尝试写下测试用例
return 0;
}
栈模拟队列(c++)
最新推荐文章于 2023-02-14 23:49:49 发布