mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 10:26:27 +08:00
栈的python代码
This commit is contained in:
parent
f8d44be73d
commit
60cb2ffc97
2 changed files with 5 additions and 4 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue