aboutsummaryrefslogtreecommitdiffstats
path: root/225/main.cpp
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-05-05 14:26:45 +0000
committerterminaldweller <thabogre@gmail.com>2022-05-05 14:26:45 +0000
commit92d7fa867ed2b0b5d80cbe32393088a6585c387a (patch)
treedcbea079d9dfa9d24d437e322c56f4f32d11bf55 /225/main.cpp
parentupdate (diff)
downloadleetcode-92d7fa867ed2b0b5d80cbe32393088a6585c387a.tar.gz
leetcode-92d7fa867ed2b0b5d80cbe32393088a6585c387a.zip
update
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;
+}