From c57cabbbd3e06a688b44554f4786153ecf3bff15 Mon Sep 17 00:00:00 2001 From: qualifier1024 <102360259+qualifier1024@users.noreply.github.com> Date: Mon, 28 Nov 2022 00:49:02 +0800 Subject: [PATCH] Update PrintUtil.hpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仿写了个stack打印 --- codes/cpp/include/PrintUtil.hpp | 46 +++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/codes/cpp/include/PrintUtil.hpp b/codes/cpp/include/PrintUtil.hpp index b85da88ef..40fefae53 100644 --- a/codes/cpp/include/PrintUtil.hpp +++ b/codes/cpp/include/PrintUtil.hpp @@ -67,22 +67,6 @@ class PrintUtil { return os.str(); } - /** - * @brief Print an Array - * - * @tparam T - * @tparam n - */ - template - static void printArray(T* arr, int n) - { - cout << "["; - for (size_t i = 0; i < n - 1; i++) { - cout << arr[i] << ", "; - } - cout << arr[n - 1] << "]" << '\n'; - } - /** * @brief Get the Vector String object * @@ -95,6 +79,25 @@ class PrintUtil { return "[" + strJoin(", ", list) + "]"; } + /** + * @brief Get the Stack String object + * + * @tparam T + * @param stack + * @return string + */ + template + static string getStackString(stack stack) { + ostringstream s; + if(!stack.empty()){ + s<" + s.str() + "]"; + } + /** * @brief Print a vector * @@ -106,6 +109,17 @@ class PrintUtil { cout << getVectorString(list) << '\n'; } + /** + * @brief Print a stack + * + * @tparam T + * @param sta + */ + template + static void printStack(stack &stack) { + cout << getStackString(stack) << '\n'; + } + /** * @brief Print a vector matrix *