From fe4af37290ad7216d1f51262698bd7aa1dae0c11 Mon Sep 17 00:00:00 2001 From: qualifier1024 <102360259+qualifier1024@users.noreply.github.com> Date: Mon, 28 Nov 2022 09:04:43 +0800 Subject: [PATCH 1/2] Update stack.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit array.cpp修改了格式问题 --- codes/cpp/chapter_stack_and_queue/stack.cpp | 34 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/codes/cpp/chapter_stack_and_queue/stack.cpp b/codes/cpp/chapter_stack_and_queue/stack.cpp index 03cac3c5a..bac778c11 100644 --- a/codes/cpp/chapter_stack_and_queue/stack.cpp +++ b/codes/cpp/chapter_stack_and_queue/stack.cpp @@ -1,8 +1,38 @@ /* * File: stack.cpp - * Created Time: 2022-11-25 - * Author: Krahets (krahets@163.com) + * Created Time: 2022-11-28 + * Author: qualifier1024 (2539244001@qq.com) */ #include "../include/include.hpp" +int main(){ + /* 初始化栈 */ + stack stack; + + /* 元素入栈 */ + stack.push(1); + stack.push(3); + stack.push(2); + stack.push(5); + stack.push(4); + cout << "栈 stack = "; + PrintUtil::printStack(stack); + + /* 访问栈顶元素 */ + int top = stack.top(); + cout << "栈顶元素 top = " << top << endl; + + /* 元素出栈 */ + stack.pop(); + cout<< "出栈元素 pop = " << top << ",出栈后 stack = "; + PrintUtil::printStack(stack); + + /* 获取栈的长度 */ + int size = stack.size(); + cout<< "栈的长度 size = " << size << endl; + + /* 判断是否为空 */ + bool empty = stack.empty(); + return 0; +} From 8b72cf5b35d3f6220de046a155d27d230633ddc3 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Mon, 28 Nov 2022 20:22:21 +0800 Subject: [PATCH 2/2] Update stack.cpp --- codes/cpp/chapter_stack_and_queue/stack.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/codes/cpp/chapter_stack_and_queue/stack.cpp b/codes/cpp/chapter_stack_and_queue/stack.cpp index bac778c11..52d0b7730 100644 --- a/codes/cpp/chapter_stack_and_queue/stack.cpp +++ b/codes/cpp/chapter_stack_and_queue/stack.cpp @@ -34,5 +34,6 @@ int main(){ /* 判断是否为空 */ bool empty = stack.empty(); + return 0; }