本文整理汇总了Python中Node.Node.right方法的典型用法代码示例。如果您正苦于以下问题:Python Node.right方法的具体用法?Python Node.right怎么用?Python Node.right使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.right方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import right [as 别名]
def build(self, array):
if len(array) > 0:
# counting the median, which is the key
median = IntervalTree.get_median_point(self, array)
# current Node
n = Node(median)
left = []
right = []
overlap = []
for i in range(0, len(array)):
if array[i].begin <= median <= array[i].end:
overlap.append(array[i])
elif array[i].end < median:
left.append(array[i])
elif array[i].begin > median:
right.append(array[i])
n.overlap_begin_sort = sorted(overlap, key=operator.attrgetter("begin"))
n.overlap_end_sort = sorted(overlap, key=operator.attrgetter("end"), reverse=True)
if self.root is None:
self.root = n
n.left = self.build(left)
n.right = self.build(right)
return n
else:
return None
示例2: build_bst
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import right [as 别名]
def build_bst(A):
if len(A) == 0:
return None
mid = len(A)/2
root = Node(A[mid])
root.left = build_bst(A[:mid])
root.right = build_bst(A[mid+1:])
return root
示例3: test_searchFullTwoLevel
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import right [as 别名]
def test_searchFullTwoLevel(self):
node = Node()
node.setKey(3)
node11 = Node()
node11.setKey(2)
node.left = node11
node12 = Node()
node12.setKey(4)
node.right = node12
node21 = Node()
node21.setKey(5)
node11.left = node21
node22 = Node()
node22.setKey(6)
node11.right = node22
node23 = Node()
node23.setKeyAndValue(7, 14)
node12.left = node23
node24 = Node()
node24.setKeyAndValue(8,16)
node12.right = node24
self.assertEqual(node.search(7).value, 14)
示例4: insert_node
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import right [as 别名]
def insert_node(root, value):
if root is None:
root = Node(value)
else:
while root.right is not None:
if value > root.value:
root = root.right
else:
root = root.left
if root.left is None:
root.left = Node(value)
else:
root.right = Node(value)
return root
示例5: build_exp_tree
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import right [as 别名]
def build_exp_tree(postfix):
root = Node(postfix[-1])
node = root
i = len(postfix)-2
while i >= 0:
next = Node(postfix[i])
if next.data in HIGHER_ORDER:
if node.right == None:
next.right = Node(postfix[i-1])
next.left = Node(postfix[i-2])
node.right = next
i-=2
else:
node.left = next
node = next
else:
if node.right == None:
node.right = next
else:
node.left = next
node = next
i-=1
return root
示例6: Node
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import right [as 别名]
if n.right:
q.append(n.right)
if n.left:
q.append(n.left)
return False
# Tree is as shows:
# 0
# 1 2
# 3 4 5
n0 = Node(0); n1 = Node(1)
n2 = Node(2); n3 = Node(3)
n4 = Node(4); n5 = Node(5)
n0.left = n1; n0.right = n2
n1.parent = n0; n2.parent = n0
n1.left = n3; n1.right = None
n3.parent = n1
n2.left = n4; n2.right = n5
n4.parent = n2; n5.parent = n2
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n4, n5)
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n3, n4)
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n3, n1)
print "The first common ancestor is: %s" % firstCommonAncestor(n0, n1, Node(0))