【问题标题】:How do you determine (code) if the stack is empty?如果堆栈为空,您如何确定(代码)?
【发布时间】: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

【问题讨论】:

标签: python data-structures stack


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2019-09-18
    • 2014-07-30
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    相关资源
    最近更新 更多