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


Python TreeNode.parent方法代码示例

本文整理汇总了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)
开发者ID:3009420,项目名称:mgipython,代码行数:14,代码来源:DagBuilder.py

示例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)
开发者ID:3009420,项目名称:mgipython,代码行数:19,代码来源:DagBuilder.py

示例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
开发者ID:aihex,项目名称:cracking-the-coding-interview-python,代码行数:33,代码来源:Q4.5.py


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