本文整理汇总了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]
示例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)
示例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))
示例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)
示例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)
示例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]
示例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]
示例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)