aboutsummaryrefslogtreecommitdiff
path: root/other/implement_queue_stacks.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/implement_queue_stacks.cpp')
-rw-r--r--other/implement_queue_stacks.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/other/implement_queue_stacks.cpp b/other/implement_queue_stacks.cpp
new file mode 100644
index 0000000..551ce9f
--- /dev/null
+++ b/other/implement_queue_stacks.cpp
@@ -0,0 +1,32 @@
+#include "leetcode.h"
+
+class MyQueue {
+public:
+ stack<int> input, output;
+ void push(int x) { input.push(x); }
+ int pop() {
+ int x = output.top();
+ peek();
+ return x;
+ }
+ int peek() {
+ if (output.empty())
+ while (input.size())
+ output.push(input.top()), input.pop();
+ return output.top();
+ }
+ bool empty() { return input.empty() && output.empty(); }
+};
+
+int main() {
+ MyQueue *obj = new MyQueue();
+ obj->push(2);
+ int param_2 = obj->pop();
+ int param_3 = obj->peek();
+ bool param_4 = obj->empty();
+ cout << param_2 << endl << param_3 << endl;
+ if (param_4)
+ cout << "true";
+ else
+ cout << "endl";
+}