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


Python Bst.insert方法代码示例

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


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

示例1: test_search

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_search():
    """Test that the search returns a node connected to the selected value."""
    from bst import Bst, Node
    new_bst = Bst()
    new_bst.insert(1)
    for item in new_bst.head._search():
        assert isinstance(item, Node)
开发者ID:jmcclena94,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例2: test_balance_right_two_nodes

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_balance_right_two_nodes():
    """Test balance right heavy."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(4)
    assert new_bst.balance() == -1
开发者ID:cacizi41,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例3: test_balance_left_two_nodes

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_balance_left_two_nodes():
    """Test balance left heavy."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(2)
    assert new_bst.balance() == 1
开发者ID:cacizi41,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例4: bst_with_stuff

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def bst_with_stuff():
    """Create BST with stuff in it."""
    from bst import Bst
    bst = Bst()
    for i in range(1, 21):
        bst.insert(i)
    return bst
开发者ID:flegald,项目名称:data_structures,代码行数:9,代码来源:test_bst.py

示例5: instance2

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def instance2():
    """Fun tree fixture."""
    fun_tree = Bst()
    insertions = [11, 17, 9, 10, 8, 7, 4, 12, 19, 18]
    for fun in insertions:
        fun_tree.insert(fun)
    return fun_tree
开发者ID:scotist,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例6: test_balance_equal

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_balance_equal():
    """Test that tree is balanced."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(2)
    new_bst.insert(4)
    assert new_bst.balance() == 0
开发者ID:cacizi41,项目名称:data-structures,代码行数:10,代码来源:test_bst.py

示例7: test_get_size

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_get_size():
    """Test the size method works."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(8)
    new_bst.insert(5)
    assert new_bst.get_size() == 3
开发者ID:cacizi41,项目名称:data-structures,代码行数:10,代码来源:test_bst.py

示例8: test_depth

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_depth():
    """Test depth works."""
    from bst import Bst
    r = range(10)
    new_bst = Bst()
    for i in r:
        new_bst.insert(i)
    assert new_bst.depth() == 10
开发者ID:cacizi41,项目名称:data-structures,代码行数:10,代码来源:test_bst.py

示例9: test_balance_left_complex

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_balance_left_complex():
    """Test a left heavy list with multiple nodes."""
    from bst import Bst
    r = range(10, 0, -1)
    new_bst = Bst()
    for i in r:
        new_bst.insert(i)
    assert new_bst.balance() == 9
开发者ID:cacizi41,项目名称:data-structures,代码行数:10,代码来源:test_bst.py

示例10: test_delete_on_complex_tree

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_delete_on_complex_tree():
    """Test that the selected node is deleted."""
    from bst import Bst
    nodes = [10, 9, 15, 2, 6, 12, 20, 1, 3]
    new_bst = Bst()
    for item in nodes:
        new_bst.insert(item)
    new_bst.delete(2)
    assert new_bst.contains(2) is False
开发者ID:jmcclena94,项目名称:data-structures,代码行数:11,代码来源:test_bst.py

示例11: test_delete_on_range

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_delete_on_range():
    """Test that the node selected is removed from the tree."""
    from bst import Bst
    new_bst = Bst()
    for items in range(20):
        new_bst.insert(items)
    new_bst.delete(10)
    assert new_bst.contains(10) is False
    assert new_bst.size == 19
开发者ID:jmcclena94,项目名称:data-structures,代码行数:11,代码来源:test_bst.py

示例12: test_delete

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_delete():
    """Test that the selected node is deleted."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(1)
    new_bst.delete(1)
    assert new_bst.contains(1) is False
    assert new_bst.head is None
    assert new_bst.size == 0
开发者ID:jmcclena94,项目名称:data-structures,代码行数:11,代码来源:test_bst.py

示例13: test_insert_two_values

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_insert_two_values():
    """Test insert works for two values."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(4)
    assert new_bst.head.value == 3
    assert new_bst.head.right.value == 4
    assert new_bst.head.left is None
开发者ID:cacizi41,项目名称:data-structures,代码行数:11,代码来源:test_bst.py

示例14: test_rotated_root_after_insert

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_rotated_root_after_insert(seq):
    """Test that value at top of tree is what we expect after rotate."""
    tree = Bst()
    expected_root_val = list(sorted(seq))[1]
    tree.insert(seq[0])
    tree.insert(seq[1])
    assert tree.value == seq[0]
    tree.insert(seq[2])
    assert tree.value == expected_root_val
开发者ID:scotist,项目名称:data-structures,代码行数:11,代码来源:test_bst.py

示例15: test_insert_value_already_exists

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import insert [as 别名]
def test_insert_value_already_exists():
    """Test if value exists it is ignored."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(3)
    assert new_bst.head.right is None
    assert new_bst.head.left is None
    assert new_bst.head.value == 3
开发者ID:cacizi41,项目名称:data-structures,代码行数:11,代码来源:test_bst.py


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