本文整理汇总了Python中bst.BinarySearchTree.right方法的典型用法代码示例。如果您正苦于以下问题:Python BinarySearchTree.right方法的具体用法?Python BinarySearchTree.right怎么用?Python BinarySearchTree.right使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.right方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: num_leaves
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import right [as 别名]
##tree i use for testing http://puu.sh/dsvBN/dbe749f41d.png
def num_leaves(T):
if T.is_empty():
return 0
elif T.left.is_empty() and T.right.is_empty():
return 1
else:
return num_leaves(T.left) + num_leaves(T.right)
a = BinarySearchTree(10)
b = BinarySearchTree(5)
c = BinarySearchTree(20)
d = BinarySearchTree(3)
e = BinarySearchTree(7)
f = BinarySearchTree(18)
g = BinarySearchTree(22)
a.left = b
a.right = c
b.left = d
b.right = e
c.left = f
c.right = g
print(num_leaves(a))
示例2: find_kth_smallest
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import right [as 别名]
return find_kth_smallest(T.right,k-left-1)
else:
return find_kth_smallest(T.left,k)
def size(T):
if T.is_empty():
return 0
else:
return 1 + size(T.left) + size(T.right)
a = BinarySearchTree(10)
b = BinarySearchTree(5)
c = BinarySearchTree(20)
d = BinarySearchTree(3)
e = BinarySearchTree(7)
f = BinarySearchTree(18)
g = BinarySearchTree(22)
a.left = b
a.right = c
b.left = d
b.right = e
c.left = f
c.right = g
print(find_kth_smallest(a,3))
示例3: size
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import right [as 别名]
__author__ = 'Udara'
from bst import BinarySearchTree, EmptyValue
##tree i use for testing http://puu.sh/dsvBN/dbe749f41d.png
def size(T):
if T.is_empty():
return 0
else:
return 1 + size(T.left) + size(T.right)
a = BinarySearchTree(10)
b = BinarySearchTree(5)
c = BinarySearchTree(20)
d = BinarySearchTree(3)
e = BinarySearchTree(7)
f = BinarySearchTree(18)
g = BinarySearchTree(22)
a.left = b
a.right = c
b.left = d
b.right = e
c.left = f
c.right = g
print(size(a))
示例4: even
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import right [as 别名]
return 0
elif T.root % 2 == 0:
return 1 + even(T.left) + even(T.right)
else:
return even(T.left) + even(T.right)
a = BinarySearchTree(10)
b = BinarySearchTree(5)
c = BinarySearchTree(20)
d = BinarySearchTree(3)
e = BinarySearchTree(7)
f = BinarySearchTree(18)
g = BinarySearchTree(22)
a.left = b
a.right = c
b.left = d
b.right = e
c.left = f
c.right = g
print(even(a))
示例5: count_all
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import right [as 别名]
#return 1 + count_all(T.left, item)
n = 1
n+= count_all(T.left,item)
return n
a = BinarySearchTree(10)
b = BinarySearchTree(5)
c = BinarySearchTree(20)
d = BinarySearchTree(3)
e = BinarySearchTree(7)
f = BinarySearchTree(18)
g = BinarySearchTree(22)
a.left = b
a.right = c
b.left = d
b.right = e
c.left = f
c.right = g
g.left = BinarySearchTree(22)
print(count_all(a,22))
示例6: num_items
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import right [as 别名]
if T.is_empty():
return 0
elif T.root != item:
return num_items(T.left,item)
else:
return 1 + num_items(T.left, item)
a = BinarySearchTree(10)
b = BinarySearchTree(5)
c = BinarySearchTree(20)
d = BinarySearchTree(3)
e = BinarySearchTree(7)
f = BinarySearchTree(18)
g = BinarySearchTree(22)
a.left = b
a.right = c
b.left = d
b.right = e
c.left = f
c.right = g
d.left = BinarySearchTree(3)
print(num_items(a,3))