스택으로 큐(StackQueue), 큐로 스택(QueueStack)


스택으로 큐(StackQueue), 큐로 스택(QueueStack)

#include <iostream> #include <stack> #include <queue> using std::cout; using std::endl; class StackQueue { private: std::stack<int> s1; std::stack<int> s2; public: void Push(int data) { s1.push(data); } int Pop() { if (s2.empty()) { while (!s1.empty()) { s2.push(s1.top()); s1.pop(); } } int data = s2.top(); s2.pop(); return data; } }; class QueueStack { private: std::queue<int> q1; std::queue<int> q2; public: void Push(int data) { if (q1.empty()) { q1.push(data); } else { while (!q1.empty()) { q...


#Queue #QueueStack #Stack #StackQueue #스택 #스택에서큐 #큐 #큐에서스택

원문링크 : 스택으로 큐(StackQueue), 큐로 스택(QueueStack)