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


Python BinarySearchTree.left方法代码示例

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


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

示例1: find_kth_smallest

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import left [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))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:11findkthsmallest.py

示例2: num_leaves

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import left [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))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:2numleaves.py

示例3: size

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import left [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))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:32,代码来源:1siize.py

示例4: even

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import left [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))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:7findeven.py

示例5: count_all

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import left [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))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:extracoutnalle.py

示例6: dupsx

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import left [as 别名]
        return dupsx(T.left, seen) + dupsx(T.right, seen)





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)
f.left = BinarySearchTree(18)
e.left = BinarySearchTree(7)
g.left = BinarySearchTree(22)

print(dups(a))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:6dupss.py

示例7: num_items

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import left [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))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:5numitem.py


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