From 60cb2ffc975fbfff0bfa91046ccc9917348281a6 Mon Sep 17 00:00:00 2001 From: pengchzn Date: Tue, 29 Nov 2022 22:58:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=88=E7=9A=84python=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/python/chapter_stack_and_queue/array_stack.py | 4 ++-- codes/python/chapter_stack_and_queue/linkedlist_stack.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/codes/python/chapter_stack_and_queue/array_stack.py b/codes/python/chapter_stack_and_queue/array_stack.py index d9243d512..58a73556a 100644 --- a/codes/python/chapter_stack_and_queue/array_stack.py +++ b/codes/python/chapter_stack_and_queue/array_stack.py @@ -21,7 +21,7 @@ class ArrayStack: return self._size """ 判断栈是否为空 """ - def isEmpty(self): + def is_empty(self): return self._stack == [] """ 入栈 """ @@ -70,4 +70,4 @@ if __name__ == "__main__": print("栈的长度 size = ", size) """ 判断是否为空 """ - isEmpty = (stack == []) + isEmpty = stack.is_empty() diff --git a/codes/python/chapter_stack_and_queue/linkedlist_stack.py b/codes/python/chapter_stack_and_queue/linkedlist_stack.py index d28f37705..88029474d 100644 --- a/codes/python/chapter_stack_and_queue/linkedlist_stack.py +++ b/codes/python/chapter_stack_and_queue/linkedlist_stack.py @@ -50,8 +50,9 @@ class LinkedListStack: stack = [] temp = self.head while temp: - stack.insert(0, temp.val) + stack.append(temp.val) temp = temp.next + stack = stack[::-1] return stack @@ -81,4 +82,4 @@ if __name__ == "__main__": print("栈的长度 size = ", size) """ 判断是否为空 """ - isEmpty = (stack == []) + isEmpty = stack.is_empty()