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


Python Tree.subtrees方法代码示例

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


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

示例1: size

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
    if T.root is EmptyValue:
        return 0
    else:
        count = 1
        for tree in T.subtrees:
            count += size(tree)
        return count






a = Tree(1)
b = Tree(2)
c = Tree(3)

d = Tree(4)
e = Tree(5)

f = Tree(6)
g = Tree(7)

h = Tree(8)

g.subtrees= [h]
c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]

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

示例2: internal_nodes

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
__author__ = 'Udara'
from tree import Tree,EmptyValue

def internal_nodes(T):
    if T.root is EmptyValue:
        return 0
    #can't use T.subtrees is [] here.
    #can't use T.subtrees is [] here.
    elif T.subtrees == []:
        return 0
    else:
        count = 1
        for trees in T.subtrees:
            count += internal_nodes(trees)
        return count




a = Tree(1)
b = Tree(2)
c = Tree(3)

d = Tree(4)
e = Tree(5)

b.subtrees = [d,e]
a.subtrees = [b,c]

print(internal_nodes(a))
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:32,代码来源:3internalnodes.py

示例3: count_dups1

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
        return count
    else:
        seen.append(T.root)
        count = 0
        for tree in T.subtrees:
            count += count_dups1(tree,seen)
        return count



a = Tree(1)
b = Tree(2)
c = Tree(3)

d = Tree(4)
e = Tree(5)

f = Tree(6)
g = Tree(7)

h = Tree(8)

i = Tree(8)
g.subtrees= [h,i]
c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]

print(count_dups(a))#1
print(count_dups(b))#0
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:32,代码来源:10countrepeated.py

示例4: count_even

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
        for tree in T.subtrees:
            count += count_even(tree)
        return count
    else:
        count = 0
        for tree in T.subtrees:
            count += count_even(tree)
        return count


a = Tree(1)
b = Tree(2)
c = Tree(3)

d = Tree(4)
e = Tree(5)

f = Tree(6)
g = Tree(7)

h = Tree(8)

i = Tree(8)

g.subtrees= [h,i]
c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]

print(count_even(a))#5
print(count_even(b))#2
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:11coutneven.py

示例5: depth

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
    assumes proper D that isn't too big or anything

    """
    if d == 0:
        return 1
    else:
        count= 0
        for trees in T.subtrees:
            count += depth(T,d-1)
        return count





a = Tree(1)
b = Tree(2)
c = Tree(3)

d = Tree(4)
e = Tree(5)

f = Tree(6)
g = Tree(7)

c.subtrees = [f,g]
b.subtrees = [d,e]
a.subtrees = [b,c]

print(depth(a,1))#2
print(depth(a,2))#4
开发者ID:udaraweerasinghege,项目名称:ADT-methods,代码行数:33,代码来源:4nodes_depth_d.py

示例6: test_has_extra_not_equal

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
 def test_has_extra_not_equal(self):
     tree2 = Tree(1)
     tree2.subtrees = [Tree('Hi'), Tree(3)]
     tree2.subtrees[0].subtrees = [Tree(2)]
     self.assertFalse(self.tree == tree2)
开发者ID:connor4312,项目名称:CSC148,代码行数:7,代码来源:test_eq_tree.py

示例7: test_missing_item_not_equal

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
 def test_missing_item_not_equal(self):
     tree2 = Tree(1)
     tree2.subtrees = [Tree(3)]
     self.assertFalse(self.tree == tree2)
开发者ID:connor4312,项目名称:CSC148,代码行数:6,代码来源:test_eq_tree.py

示例8: test_order_matters

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
 def test_order_matters(self):
     tree2 = Tree(1)
     tree2.subtrees = [Tree(3), Tree('Hi')]
     self.assertFalse(self.tree == tree2)
开发者ID:connor4312,项目名称:CSC148,代码行数:6,代码来源:test_eq_tree.py

示例9: test_simple_eq

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import subtrees [as 别名]
 def test_simple_eq(self):
     tree2 = Tree(1)
     tree2.subtrees = [Tree('Hi'), Tree(3)]
     self.assertTrue(self.tree == tree2)
开发者ID:connor4312,项目名称:CSC148,代码行数:6,代码来源:test_eq_tree.py


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