本文整理汇总了Python中LinkedList.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.isEmpty方法的具体用法?Python LinkedList.isEmpty怎么用?Python LinkedList.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.isEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StackList
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import isEmpty [as 别名]
class StackList(object):
"""Clase stack implementada sobre LinkedList"""
def __init__(self):
""" Crea una LinkedList vacia"""
self.llista = LinkedList()
def push(self, data):
""" Agrega un elemento a la pila"""
self.llista.insertBefore(data)
def pop(self):
""" Saca un elemento de la pila y lo retorna"""
if self.llista.isEmpty(): raise IndexError, "La pila esta vacia"
aux = self.llista.getHead()
self.llista.remove()
return aux
def head(self):
""" Devuelve el primer elemento que saldra de la pila, pero no lo borra """
if self.llista.isEmpty(): raise IndexError, "La pila esta vacia"
return self.llista.getHead()
def purge(self):
""" Elimina todos los elementos de la pila"""
self.llista.clear()
def __len__(self):
""" Numero de elementos de la pila"""
return self.llista.getSize()
def __str__(self):
""" Devuelve una cadena de caracteres """
return str(self.llista)
示例2: Node
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import isEmpty [as 别名]
class Node(object):
"""
Class Node
"""
def __init__(self, data):
"""
Initialize node.
:param data: Data of new node.
"""
self.data = data
self.childs = LinkedList()
def addChild(self, child):
"""
Add a new child at the end of the Node's LinkedList.
:param child: The new child to add.
"""
self.childs.insertAfter(child)
def getChilds(self):
"""
Get all childs of tree's node.
:return : Node's LinkedList.
"""
return self.childs
def getData(self):
"""
Get data of Tree's node.
:return : Agregar comentarios
"""
return self.data
def getChild(self, data):
"""
Get one child in a Node's LinkedList.
:param data: The data to search into LinkedList.
:return : The child (Tree.Node) or None if not found
"""
#Firstly, we check if LinkedList is empty.
if (self.childs.isEmpty()):
return None
else:
self.childs.moveHead()
#So getCurrent() return a Tree's node we should call a getData method of Tree's node to get the real data.
while ((data != self.childs.getCurrent().getData() and (self.childs.current.getNext() != None))):
self.childs.moveNext()
#If we found the data, it returns the current node.
if (data == self.childs.getCurrent().getData()):
return self.childs.getCurrent()
else:
return None
def __str__(self):
"""
Get all elements of LinkedList in string format.
:return : Agregar comentarios
"""
return self.strRecursive('', True)
def strRecursive(self, prefix, final):
"""
Recurcive method that prints the node and all of its children
:param prefix: string used for identation
:param final: boolean for printing line to the children
:return : string
"""
if final:
contingut = prefix + '└── ' + str(self.data) + '\n'
mascara = prefix + ' '
else:
contingut = prefix + '├── ' + str(self.data) + '\n'
mascara = prefix + '│ '
if self.childs.getSize() > 0:
self.childs.moveHead()
for idx in range(self.childs.getSize() - 1):
contingut += self.childs.getCurrent().strRecursive(mascara, False)
self.childs.moveNext()
contingut += self.childs.getCurrent().strRecursive(mascara, True)
return contingut