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