From 7f8946ce7af55a88088f3fb770176e75db75bbc8 Mon Sep 17 00:00:00 2001 From: Eatswap Date: Mon, 28 Aug 2023 23:58:03 +0800 Subject: [PATCH] add: 230828 --- cpp/2308/LC230828.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ cpp/2308/defs.h | 14 ++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 cpp/2308/LC230828.cpp diff --git a/cpp/2308/LC230828.cpp b/cpp/2308/LC230828.cpp new file mode 100644 index 0000000..b4d0f3d --- /dev/null +++ b/cpp/2308/LC230828.cpp @@ -0,0 +1,40 @@ +#include + +class LC230828 { +private: + std::queue q; + +public: + LC230828(); + void push(int x); + int pop(); + int top(); + bool empty(); +}; + +LC230828::LC230828() = default; + +void LC230828::push(int x) { + int n = q.size(); + q.push(x); + while (n--) { + q.push(q.front()); + q.pop(); + } +} + +int LC230828::pop() { + int ret = q.front(); + q.pop(); + return ret; +} + +int LC230828::top() { + return q.front(); +} + +bool LC230828::empty() { + return q.empty(); +} + + diff --git a/cpp/2308/defs.h b/cpp/2308/defs.h index 177a252..61c40de 100644 --- a/cpp/2308/defs.h +++ b/cpp/2308/defs.h @@ -1,6 +1,7 @@ #ifndef LEETCODE_CPP_DEFS_H #define LEETCODE_CPP_DEFS_H +#include #include class LC230827 { @@ -8,4 +9,17 @@ public: static bool canCross(const std::vector&); }; +class LC230828 { +private: + std::queue q; + +public: + LC230828(); + void push(int x); + int pop(); + int top(); + bool empty(); +}; + + #endif //LEETCODE_CPP_DEFS_H