From b9e97d3823d7156ba2cd3f3c9153f98905d2dc3e Mon Sep 17 00:00:00 2001 From: Gonglja <39959756+Gonglja@users.noreply.github.com> Date: Mon, 20 Mar 2023 21:26:20 +0800 Subject: [PATCH] Fix access error when printArray(arr, 0) (#432) * fix(codes/cpp): Memory leak fix: the space was not freed when pop removed the element. * fix(codes/cpp): Fix access error when printArray(arr, 0) * Update PrintUtil.hpp --------- Co-authored-by: Yudong Jin --- codes/cpp/include/PrintUtil.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codes/cpp/include/PrintUtil.hpp b/codes/cpp/include/PrintUtil.hpp index a76f7a80a..252822899 100644 --- a/codes/cpp/include/PrintUtil.hpp +++ b/codes/cpp/include/PrintUtil.hpp @@ -102,7 +102,7 @@ class PrintUtil { for (int i = 0; i < n - 1; i++) { cout << arr[i] << ", "; } - if (n>=1) + if (n >= 1) cout << arr[n - 1] << "]" << endl; else cout << "]" << endl;