aboutsummaryrefslogtreecommitdiffstats
path: root/225/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--225/main.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/225/main.cpp b/225/main.cpp
new file mode 100644
index 0000000..13b7d6c
--- /dev/null
+++ b/225/main.cpp
@@ -0,0 +1,49 @@
+#include "header.hpp"
+#include <queue>
+
+class MyStack {
+public:
+ MyStack() = default;
+
+ void push(int x) { q1.push(x); }
+
+ int pop() {
+ while (q1.size() > 1) {
+ q2.push(q1.front());
+ q1.pop();
+ }
+ auto result = q1.back();
+ q1.pop();
+ while (q2.size() > 0) {
+ q1.push(q2.front());
+ q2.pop();
+ }
+ return result;
+ }
+
+ int top() { return q1.back(); }
+
+ bool empty() { return q1.empty(); }
+
+private:
+ std::queue<int> q1;
+ std::queue<int> q2;
+};
+
+/**
+ * Your MyStack object will be instantiated and called as such:
+ * MyStack* obj = new MyStack();
+ * obj->push(x);
+ * int param_2 = obj->pop();
+ * int param_3 = obj->top();
+ * bool param_4 = obj->empty();
+ */
+
+int main(int argc, char **argv) {
+ MyStack *obj = new MyStack();
+ obj->push(10);
+ int param_2 = obj->pop();
+ int param_3 = obj->top();
+ bool param_4 = obj->empty();
+ return 0;
+}