您如何确定(编码)堆栈是否为空?

时间:2019-05-19 21:34:53

标签: python data-structures stack

我正在学习数据结构,目前正在堆栈上工作。我想知道您如何确定堆栈是否为空?

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

1 个答案:

答案 0 :(得分:0)

如果self._values为空列表,则堆栈为空