本文整理汇总了Python中LinkedList.moveNext方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.moveNext方法的具体用法?Python LinkedList.moveNext怎么用?Python LinkedList.moveNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList.moveNext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Node
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import moveNext [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
示例2: Node
# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import moveNext [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