From 92d7fa867ed2b0b5d80cbe32393088a6585c387a Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Thu, 5 May 2022 18:56:45 +0430 Subject: update --- 225/main.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 225/main.cpp (limited to '225/main.cpp') 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 + +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 q1; + std::queue 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; +} -- cgit v1.2.3