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


Python BST.pre_order方法代码示例

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


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

示例1: test_pre_order_empty

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import pre_order [as 别名]
def test_pre_order_empty():
    """Test an empty Node returns empty list."""
    from bst import BST
    b = BST()
    pre_ord = b.pre_order()
    pre_ord_list = []
    for ii in pre_ord:
        pre_ord_list.append(ii)
    assert pre_ord_list == []
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:11,代码来源:test_bst.py

示例2: test_pre_order_solo

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import pre_order [as 别名]
def test_pre_order_solo():
    """Test running pre-order on a tree with one Node."""
    from bst import BST
    b = BST([132])
    pre_ord = b.pre_order()
    pre_ord_list = []
    for ii in pre_ord:
        pre_ord_list.append(ii)
    assert pre_ord_list == [132]
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:11,代码来源:test_bst.py

示例3: test_delete_middle_of_tree

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import pre_order [as 别名]
def test_delete_middle_of_tree():
    t = BST()
    t.insert(3)
    t.insert(2)
    t.insert(5)
    t.insert(1)
    t.insert(4)
    t.insert(6)
    t.insert(7)
    t.delete(5)
    assert list(t.pre_order()) == [3, 2, 1, 6, 4, 7]
开发者ID:kaka0525,项目名称:data-strutctures-partII,代码行数:13,代码来源:test_bst.py

示例4: test_pre_post_order_traversal

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import pre_order [as 别名]
def test_pre_post_order_traversal():
    """Tests both pre and post-order traversal"""
    import types
    bintree = BST()

    with pytest.raises(TypeError):
        bintree.pre_order(1)  # No args/kwargs
    with pytest.raises(TypeError):
        bintree.pre_order(None)

    assert isinstance(bintree.pre_order(), types.GeneratorType)

    with pytest.raises(TypeError):
        bintree.post_order(1)  # No args/kwargs
    with pytest.raises(TypeError):
        bintree.post_order(None)

    assert isinstance(bintree.post_order(), types.GeneratorType)

    bintree.insert(5)
    bintree.insert(3)
    bintree.insert(7)
    bintree.insert(6)
    bintree.insert(2)
    bintree.insert(4)
    bintree.insert(1)
    bintree.insert(9)
    bintree.insert(10)
    #      5
    #    /   \
    #   3     7
    #  /\    / \
    # 2  4  6   9
    # |         |
    # 1         10
    pre_gen = bintree.pre_order()
    post_gen = bintree.post_order()

    assert pre_gen.next() == 5
    assert pre_gen.next() == 3
    assert pre_gen.next() == 2
    assert pre_gen.next() == 1
    assert pre_gen.next() == 4
    assert pre_gen.next() == 7
    assert pre_gen.next() == 6
    assert pre_gen.next() == 9
    assert pre_gen.next() == 10

    assert post_gen.next() == 1
    assert post_gen.next() == 2
    assert post_gen.next() == 4
    assert post_gen.next() == 3
    assert post_gen.next() == 6
    assert post_gen.next() == 10
    assert post_gen.next() == 9
    assert post_gen.next() == 7
    assert post_gen.next() == 5

    with pytest.raises(StopIteration):
        pre_gen.next()

    with pytest.raises(StopIteration):
        post_gen.next()
开发者ID:jbbrokaw,项目名称:data-structures,代码行数:65,代码来源:test_bst.py


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