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


Python BTNode.left方法代码示例

本文整理汇总了Python中btNode.BTNode.left方法的典型用法代码示例。如果您正苦于以下问题:Python BTNode.left方法的具体用法?Python BTNode.left怎么用?Python BTNode.left使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在btNode.BTNode的用法示例。


在下文中一共展示了BTNode.left方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n15 = BTNode(15)
    n7  = BTNode(7)
    n30 = BTNode(30)
    n11 = BTNode(11)
    n9  = BTNode(9)
    n8  = BTNode(8)
    n10 = BTNode(10)
    n14 = BTNode(14)
    n13 = BTNode(13)
    n12 = BTNode(12)

    n15.left = n7
    n15.right = n30
    n7.right = n11
    n11.left = n9
    n11.right = n14
    n9.left = n8
    n9.right = n10
    n11.right = n14
    n14.left = n13
    n13.left = n12
    print(lcaBST(n15, n8, n12).val)
    print(lcaBST(n15, n13, n12).val)
    print(lcaBST(n15, n7, n12).val)
开发者ID:victorfei,项目名称:interview,代码行数:27,代码来源:lowestCommonAncesBST.py

示例2: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n11 = BTNode(11)
    n8  = BTNode(8)
    n4  = BTNode(4)
    n1  = BTNode(1)
    n5  = BTNode(5)
    n6  = BTNode(6)
    n7  = BTNode(7)
    n16 = BTNode(16)
    n14 = BTNode(14)
    n15 = BTNode(15)
    n12 = BTNode(12)
    n13 = BTNode(13)

    n11.left = n8
    n8.left = n4
    n4.left = n1
    n4.right = n5
    n5.right = n6
    n6.right = n7
    n11.right = n16
    n16.left = n14
    n14.left = n12
    n14.right = n15
    n12.right = n13

    res = inorderBSTSuccessor(n11, n7)
    val = None if not res else res.val
    print(val)
    print('----------')
    res = inorderBSTSuccessor(n11, n12)
    val = None if not res else res.val
    print(val)
    print('=============')
开发者ID:victorfei,项目名称:interview,代码行数:36,代码来源:bstSuccessorNode.py

示例3: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n1  = BTNode(1)
    n2  = BTNode(2)
    n3  = BTNode(3)
    n4  = BTNode(4)
    n5  = BTNode(5)
    n6  = BTNode(6)
    n7  = BTNode(7)
    n8  = BTNode(8)
    n9  = BTNode(9)
    n10 = BTNode(10)
    n11 = BTNode(11)

    n1.left = n2
    n1.right = n3
    n2.left = n4
    n2.right = n5
    n4.left = n6
    n4.right = n7
    n3.left = n8
    n3.right = n9
    n8.left = n10
    n8.right = n11
    print(pot(n1))
    print(pot_stack(n1))
开发者ID:victorfei,项目名称:interview,代码行数:27,代码来源:preorderTrav.py

示例4: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n7 = BTNode(7)
    n10 = BTNode(10)
    n4 = BTNode(4)
    n3 = BTNode(3)
    n1 = BTNode(1)
    n2 = BTNode(2)
    n8 = BTNode(8)
    n11 = BTNode(11)

    n7.left = n10
    n7.right = n2
    n10.left = n4
    n10.right = n3
    n3.right = n1
    n2.left = n8
    n8.left = n11

    BTNode.print_nodes(n7)

    print('-----------------------------')
    post_o = [4, 1, 3, 10, 11, 8, 2, 7]
    in_o = [4, 10, 3, 1, 7, 11, 8, 2]
    BTNode.print_nodes(buildT(post_o, in_o))

    print('-----------------------------')
    post_o = [4, 1, 3, 10, 11, 8, 2, 7]
    in_o = [4, 10, 3, 1, 7, 11, 8, 2]
    BTNode.print_nodes(buildTFaster(post_o, in_o))
    print('-----------------------------')
开发者ID:victorfei,项目名称:interview,代码行数:32,代码来源:buildTreePostInorder.py

示例5: test2

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test2():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)
    n4 = BTNode(4)

    n1.left = n2
    n2.left = n3
    n3.left = n4
    print(isBalBST(n1))
开发者ID:victorfei,项目名称:interview,代码行数:12,代码来源:isBSTBalanced.py

示例6: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n3 = BTNode(3)
    n9 = BTNode(9)
    n20 = BTNode(20)
    n15 = BTNode(15)
    n7 = BTNode(7)
    n3.left = n9
    n3.right = n20
    n20.left = n15
    n20.right = n7
    print(zzTrav(n3))
开发者ID:victorfei,项目名称:interview,代码行数:13,代码来源:zigZagTraverse.py

示例7: test2

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test2():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)

    n1.left = n2
    n2.left = n3

    flatten(n1)
    BTNode.print_nodes(n1)
    print('--------------------------')
开发者ID:victorfei,项目名称:interview,代码行数:13,代码来源:treeToLinkedList.py

示例8: test3

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test3():
    n5 = BTNode(5)
    n4 = BTNode(4)
    n9 = BTNode(9)
    n7 = BTNode(7)
    n2 = BTNode(2)

    n5.left = n4
    n4.left = n9
    n9.left = n7
    n5.right = n2
    print(sumRoot2LeafNumbers(n5))
开发者ID:victorfei,项目名称:interview,代码行数:14,代码来源:sumRoot2LeafNumbers.py

示例9: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)
    n4 = BTNode(4)

    n1.left = n2
    n1.right = n3
    n2.left = n4

    print(constructStr(n1))
    print(constructStr2_top(n1))
开发者ID:victorfei,项目名称:interview,代码行数:14,代码来源:stringFromBinaryTree.py

示例10: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n3 =  BTNode(3)
    n9 =  BTNode(9)
    n20 = BTNode(20)
    n15 = BTNode(15)
    n7 =  BTNode(7)
    n3.left = n9
    n3.right = n20
    n20.left = n15
    n20.right = n7

    lst = []
    lot(n3, 0, lst)
    print(lst)
开发者ID:victorfei,项目名称:interview,代码行数:16,代码来源:levelOrderTraversal.py

示例11: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)
    n4 = BTNode(4)
    n5 = BTNode(5)
    n6 = BTNode(6)

    n3.left = n2
    n3.right = n5
    n2.left = n1
    n5.left = n4
    n5.right = n6

    print(isBalBST(n3))
开发者ID:victorfei,项目名称:interview,代码行数:17,代码来源:isBSTBalanced.py

示例12: test2

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test2():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n3 = BTNode(3)
    n4 = BTNode(4)
    n5 = BTNode(5)

    n1.left = n2
    n2.right = n3
    n3.right = n4
    n4.left = n5

    lst = []
    lot(n1, 0, lst)
    print(lst)
开发者ID:victorfei,项目名称:interview,代码行数:17,代码来源:levelOrderTraversal.py

示例13: test1

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test1():
    n1 = BTNode(1)
    n2 = BTNode(2)
    n5 = BTNode(5)
    n7 = BTNode(7)
    n9 = BTNode(9)
    n8 = BTNode(8)

    n1.left = n2
    n2.left = n5
    n2.right = n9
    n5.left = n7
    n9.left = n8

    print(rightView(n1))
开发者ID:victorfei,项目名称:interview,代码行数:17,代码来源:rightView.py

示例14: test2

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def test2():
    n1 = BTNode(1)
    n2 = BTNode(2)

    n1.left = n2
    print(pathSum(n1, 0, 1))
    print(pathSumAlt(n1, 1))
开发者ID:victorfei,项目名称:interview,代码行数:9,代码来源:sumPath.py

示例15: buildTHelper

# 需要导入模块: from btNode import BTNode [as 别名]
# 或者: from btNode.BTNode import left [as 别名]
def buildTHelper(post_o, in_o, idx_dic, beg, end):
    if beg < end:
        mid = idx_dic[post_o.pop()]
        n = BTNode(in_o[mid])
        n.right = buildTHelper(post_o, in_o, idx_dic, mid+1, end)
        n.left = buildTHelper(post_o, in_o, idx_dic, beg, mid)

        return n
开发者ID:victorfei,项目名称:interview,代码行数:10,代码来源:buildTreePostInorder.py


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