当前位置: 首页>>代码示例>>Python>>正文


Python LinkedList.remove_at方法代码示例

本文整理汇总了Python中LinkedList.remove_at方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.remove_at方法的具体用法?Python LinkedList.remove_at怎么用?Python LinkedList.remove_at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkedList的用法示例。


在下文中一共展示了LinkedList.remove_at方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Stack

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import remove_at [as 别名]
class Stack(IReadOnlyCollection):
    """ Represents a generic stack. """
    # Remarks:
    # T is the type of item on the stack.

    def __init__(self, dataContainer = None):
        """ Creates a new stack instance that uses the specified list to store its data. """
        if dataContainer is None:
            self.data_container = None
            self.data_container = LinkedList()
            return
        self.data_container = dataContainer

    def push(self, Item):
        """ Pushes an item on the stack. """
        self.data_container.insert(0, Item)

    def pop(self):
        """ Pops the item at the top of the stack. """
        # Pre:
        # The stack may not be empty.
        # Post:
        # If the stack was empty, the stack's state will not change, and None will be returned.
        if self.is_empty:
            return None
        value = self.data_container[0]
        self.data_container.remove_at(0)
        return value

    def __iter__(self):
        """ Creates an iterator that iterates over every element in the collection. """
        return self.data_container.__iter__()

    @property
    def is_empty(self):
        """ Gets a boolean value that indicates whether the stack is empty or not. """
        return self.count == 0

    @property
    def count(self):
        """ Gets the number of items on the stack. """
        return self.data_container.count

    @property
    def top(self):
        """ Peeks at the item at the top of the stack, without removing it. """
        # Pre:
        # The stack may not be empty.
        # Post:
        # If the stack was empty, None will be returned.
        if self.is_empty:
            return None
        else:
            return self.data_container[0]
开发者ID:jonathanvdc,项目名称:datastructures-project,代码行数:56,代码来源:Stack.py


注:本文中的LinkedList.remove_at方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。