aboutsummaryrefslogtreecommitdiff
path: root/stack_using_queues.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'stack_using_queues.cpp')
-rw-r--r--stack_using_queues.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/stack_using_queues.cpp b/stack_using_queues.cpp
new file mode 100644
index 0000000..61e2c88
--- /dev/null
+++ b/stack_using_queues.cpp
@@ -0,0 +1,24 @@
+#include "leetcode.h"
+
+class MyStack {
+public:
+ queue<int> q;
+ MyStack() {}
+ void push(int x) {
+ int n = q.size();
+ q.push(x);
+ while (n--) {
+ q.push(q.front());
+ q.pop();
+ }
+ }
+ int pop() {
+ int ans = top();
+ q.pop();
+ return ans;
+ }
+ int top() { return q.front(); }
+ bool empty() { return q.empty(); }
+};
+
+int main() {}