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


Python Node.setLeft方法代码示例

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


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

示例1: main

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
def main():
    #Test case 1

    root = Node("Max", 23)
    john = root.setLeft(Node("John", 18))
    mark = john.setRight(Node("Ann", 22)).setRight(Node("Mark", 2))
    rob = john.setLeft(Node("Rob", 12))
    rob.setRight(Node("Bob", 4)).setLeft(Node("Mie", 6))
    rob.setLeft(Node("Steven", 3)).setRight(Node("Sarah", 2))
    annie = mark.setLeft(Node("Annie", 9))
    annie.setRight(Node("Barnie", 42))
    annie.setLeft(Node("Malcolm", 7)).setRight(Node("Susan", 5)).setRight(Node("Terry", 4))

    assert root.left.right.right.left.right.name == "Barnie"
    assert root.left.left.left.name == "Steven"
    assert root.left.right.name == "Ann"
    assert root.left.right.left == None
    assert root.left.left.right.left.name == "Mie"

    maxRating, invitedPeople = FindMaxRating(root)

    assert maxRating == 109
    assert [n.name for n in invitedPeople] == ['Steven', 'Sarah', 'Mie', 'John', 'Ann', 'Malcolm', 'Susan', 'Terry', 'Barnie']

    print "Max rating for people {" + ", ".join(root.allChildren()) + "}: \n" + str(maxRating)
    print "People invited: "
    print [n.name for n in invitedPeople]
开发者ID:yurippe,项目名称:School,代码行数:29,代码来源:TestCase1.py

示例2: r

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
    def r():
        root = Node("Max", 10000)
        john = root.setLeft(Node("John", 1))
        annie = john.setLeft(Node("Annie", 1))
        jens = annie.setLeft(Node("Jens", 10000))

        FindMaxRating(root)
开发者ID:yurippe,项目名称:School,代码行数:9,代码来源:TestCase3.py

示例3: __insert

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
    def __insert(self, root, value):
        if root == None:
            root = Node(value)
            print(root.getValue())
            return

        # Go to the right if value >= value of the root
        if value >= root.getValue():
            if root.getRight():
                self.__insert(root.getRight(), value)
            else:
                root.setRight(Node(value))
        else:
            if root.getLeft():
                self.__insert(root.getLeft(), value)
            else:
                root.setLeft(Node(value))
开发者ID:paolo215,项目名称:problems,代码行数:19,代码来源:binary_search_tree_problems.py

示例4: r

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
    def r():
        root = Node("Max", -2)
        john = root.setLeft(Node("John", 18))
        mark = john.setRight(Node("Ann", 22)).setRight(Node("Mark", 2))
        rob = john.setLeft(Node("Rob", 12))
        rob.setRight(Node("Bob", 4)).setLeft(Node("Mie", 6))
        annie = mark.setLeft(Node("Annie", 9))
        annie.setRight(Node("Barnie", 42))

        FindMaxRating(root)
开发者ID:yurippe,项目名称:School,代码行数:12,代码来源:TestCase4.py

示例5: r

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
    def r():
        root = Node("Max", 23)
        john = root.setLeft(Node("John", 18))
        mark = john.setRight(Node("Ann", 22)).setRight(Node("Mark", 2))
        rob = john.setLeft(Node("Rob", 12))
        rob.setRight(Node("Bob", 4)).setLeft(Node("Mie", 6))
        rob.setLeft(Node("Steven", 3)).setRight(Node("Sarah", 2))
        annie = mark.setLeft(Node("Annie", 9))
        annie.setRight(Node("Barnie", 42))
        annie.setLeft(Node("Malcolm", 7)).setRight(Node("Susan", 5)).setRight(Node("Terry", 4))

        FindMaxRating(root)
开发者ID:yurippe,项目名称:School,代码行数:14,代码来源:TestCase1.py

示例6: main

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
def main():
    #Test case 2

    root = Node("Max", 3)
    john = root.setLeft(Node("John", 2))
    annie = john.setLeft(Node("Annie", 1))

    assert root.name == "Max"
    assert root.left.name == "John"
    assert root.left.rating == 2
    assert root.left.left.name == "Annie"
    assert root.left.right == None
    assert root.left.left.left == None

    maxRating, invitedPeople = FindMaxRating(root)

    assert maxRating == 4
    assert [n.name for n in invitedPeople] == ['Annie', 'Max']

    print "Max rating for people {" + ", ".join(root.allChildren()) + "}: \n" + str(maxRating)
    print "People invited: "
    print [n.name for n in invitedPeople]
开发者ID:yurippe,项目名称:School,代码行数:24,代码来源:TestCase2.py

示例7: main

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
def main():
    #Test case 4

    root = Node("Max", -2)
    john = root.setLeft(Node("John", 18))
    mark = john.setRight(Node("Ann", 22)).setRight(Node("Mark", 2))
    rob = john.setLeft(Node("Rob", 12))
    rob.setRight(Node("Bob", 4)).setLeft(Node("Mie", 6))
    annie = mark.setLeft(Node("Annie", 9))
    annie.setRight(Node("Barnie", 42))

    assert root.left.right.right.left.right.name == "Barnie"
    assert root.left.right.name == "Ann"
    assert root.left.right.left == None
    assert root.left.left.right.left.name == "Mie"

    maxRating, invitedPeople = FindMaxRating(root)

    assert maxRating == 91
    assert [n.name for n in invitedPeople] == ['Rob', 'Mie', 'Ann', 'Annie', 'Barnie']

    print "Max rating for people {" + ", ".join(root.allChildren()) + "}: \n" + str(maxRating)
    print "People invited: "
    print [n.name for n in invitedPeople]
开发者ID:yurippe,项目名称:School,代码行数:26,代码来源:TestCase4.py

示例8: r

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import setLeft [as 别名]
    def r():
        root = Node("Max", 3)
        john = root.setLeft(Node("John", 2))
        annie = john.setLeft(Node("Annie", 1))

        FindMaxRating(root)
开发者ID:yurippe,项目名称:School,代码行数:8,代码来源:TestCase2.py


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