【发布时间】:2019-10-06 07:23:43
【问题描述】:
我正在学习数据结构,目前正在研究堆栈。我想知道您如何确定堆栈是否为空?
from copy import deepcopy
class Stack:
def __init__(self):
"""
-------------------------------------------------------
Initializes an is_empty stack. Data is stored in a Python list.
Use: s = Stack()
-------------------------------------------------------
Returns:
a new Stack object (Stack)
-------------------------------------------------------
"""
self._values = []
def is_empty(self):
"""
-------------------------------------------------------
Determines if the stack is empty.
Use: b = s.is_empty()
-------------------------------------------------------
Returns:
True if the stack is empty, False otherwise
-------------------------------------------------------
"""
# Your code here
【问题讨论】:
-
如果
self._values是一个空列表,则栈为空。 -
这正是你应该锻炼的,这就是任务的重点。
标签: python data-structures stack