當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。