本文整理汇总了Python中TreeNode.TreeNode.parent方法的典型用法代码示例。如果您正苦于以下问题:Python TreeNode.parent方法的具体用法?Python TreeNode.parent怎么用?Python TreeNode.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode.TreeNode
的用法示例。
在下文中一共展示了TreeNode.parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadFirstChildren
# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import parent [as 别名]
def loadFirstChildren(root, foundNodes, batchloadOn):
# get immediate children
# batch load nodes of each fetched edge
if batchloadOn:
batchLoadAttribute(root.dagnode.child_edges, "child_node")
for edge in root.dagnode.child_edges:
child_node = edge.child_node
ctree_node = TreeNode(child_node)
ctree_node.parent = root
ctree_node.edge_label = edge.label
root.children.append(ctree_node)
foundNodes.add(child_node)
示例2: loadSiblings
# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import parent [as 别名]
def loadSiblings(originalNode, currentNode, foundNodes, batchloadOn):
# expand first parent to load siblings
if batchloadOn:
batchLoadAttribute(currentNode.dagnode.child_edges, "child_node")
currentNode.children = []
for edge in currentNode.dagnode.child_edges:
child_node = edge.child_node
ctree_node = TreeNode(child_node)
# preserve original node structure in order
if ctree_node._term_key == originalNode._term_key:
ctree_node = originalNode
ctree_node.parent = currentNode
ctree_node.edge_label = edge.label
currentNode.children.append(ctree_node)
foundNodes.add(child_node)
示例3: find_successor
# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import parent [as 别名]
tmp = tmp.right
return tmp.val
else:
tmp = node
while tmp.parent and tmp == tmp.parent.left:
tmp = tmp.parent
if not tmp.parent:
return None
return tmp.parent.val
if __name__ == '__main__':
# print find_successor(None)
n1 = TreeNode(8)
n2 = TreeNode(2)
n1.left = n2
n2.parent = n1
n3 = TreeNode(3)
n4 = TreeNode(4)
n2.right = n4
n4.parent = n2
n4.left = n3
n3.parent = n4
n6 = TreeNode(6)
n5 = TreeNode(5)
n4.right = n6
n6.parent = n4
n6.left = n5
n5.parent = n6
n7 = TreeNode(7)
n6.right = n7
n7.parent = n6