本文整理汇总了Python中LinkedList.getSize方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.getSize方法的具体用法?Python LinkedList.getSize怎么用?Python LinkedList.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.getSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StackList
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import getSize [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: StackList
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import getSize [as 别名]
class StackList(object):
"""
StackList
"""
def __init__(self):
self.llista=LinkedList() # Initialize value
"""
Introdueix un element a la llista utilitzant el metode de la LinkedList.
:param:data, dada a introduir
:return: None
"""
def push(self, data):
# Type code here
self.llista.insertAfter(data)
"""
Extreu un element a la llista utilitzant el metode de la LinkedList.
:return: data Conte l'informació del node
"""
def pop(self):
# Type code here
data=self.llista.getTail()
self.llista.remove();
return data;
"""
Retorna l'element el primer element de la pila.
:return: data
"""
def head(self):
# Type code here
return self.llista.getTail()
"""
Esborra el contingut de tota la pila.
:return: None
"""
def purge(self):
self.llista.clear()
"""
Metode que s'utilitza per implementar la funcio len(). .
:param:data, dada a introduir
:return: int Longitud de la pila
"""
def __len__(self):
# Type code here
return self.llista.getSize()
"""
Metode que s'utilitza per implementar la funcio print().
:return string Retorna una cadena amb tots els elements de la pila.
"""
def __str__(self):
# Type code here
return self.llista.__str__()
示例3: Node
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import getSize [as 别名]
class Node(object):
"""
Class Node
"""
def __init__(self, data):
"""
Builder of class Node, intializes each node with the parametre data
and creates and empty list for childs
:param data: what wants to be stored in the node
"""
self.data = data
self.childs = LinkedList()
def addChild(self, child):
"""
Adds node child to the list childs
:param child: Node to be added
"""
self.childs.insertAfter(child)
def getChilds(self):
"""
Returns the list of nodes childs
:return : LinkedList of nodes childs
"""
return self.childs
def getData(self):
"""
Returns data of node
:return : data of the node
"""
return self.data
def getChild(self, data):
"""
Searches child node that contains data and
return this node or None if not found
:param data: Data to search
:return : the child (Tree.Node) or None if not found
"""
aux = self.childs.head
while aux != None:
if aux.getData().getData() == data:
return aux.getData()
else:
aux = aux.getNext()
return None
def __str__(self):
"""
Creates string with the data of the node
:return : string with data of the node
"""
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
示例4: Node
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import getSize [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