我正在学习数据结构,目前正在堆栈上工作。我想知道您如何确定堆栈是否为空?
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
答案 0 :(得分:0)
如果self._values
为空列表,则堆栈为空