當前位置: 首頁>>代碼示例>>Python>>正文


Python Bst.delete方法代碼示例

本文整理匯總了Python中bst.Bst.delete方法的典型用法代碼示例。如果您正苦於以下問題:Python Bst.delete方法的具體用法?Python Bst.delete怎麽用?Python Bst.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bst.Bst的用法示例。


在下文中一共展示了Bst.delete方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_delete_on_complex_tree

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [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

示例2: test_delete_on_range

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [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

示例3: test_delete

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [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

示例4: test_rotated_root_after_delete_l2

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [as 別名]
def test_rotated_root_after_delete_l2():
    """Test that tree rotates as expected after deleting from heavier side."""
    tree = Bst()
    for val in [4, 5, 2, 3]:
        tree.insert(val)
    assert tree.value == 4
    tree.delete(5)
    assert all([tree.value == 3,
                tree.left_child.value == 2,
                tree.right_child.value == 4])
開發者ID:scotist,項目名稱:data-structures,代碼行數:12,代碼來源:test_bst.py

示例5: test_rotated_root_after_delete_ll

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [as 別名]
def test_rotated_root_after_delete_ll():
    """Test that tree rotates as expected after deleting from heavier side."""
    tree = Bst()
    for val in [3, 4, 2, 1]:
        tree.insert(val)
    assert tree.value == 3
    tree.delete(4)
    assert all([tree.value == 2,
                tree.left_child.value == 1,
                tree.right_child.value == 3])
開發者ID:scotist,項目名稱:data-structures,代碼行數:12,代碼來源:test_bst.py

示例6: test_rotated_root_after_delete_rl

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [as 別名]
def test_rotated_root_after_delete_rl():
    """Test that tree rotates as expected after deleting from lighter side."""
    tree = Bst()
    for val in [2, 1, 5, 4]:
        tree.insert(val)
    assert tree.value == 2
    tree.delete(1)
    assert all([tree.value == 4,
                tree.left_child.value == 2,
                tree.right_child.value == 5])
開發者ID:scotist,項目名稱:data-structures,代碼行數:12,代碼來源:test_bst.py

示例7: test_edge_cases_delete_tree

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [as 別名]
def test_edge_cases_delete_tree():
    """Test deletion on tree from EdgeCases example tree."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(10)
    new_bst.insert(20)
    new_bst.insert(5)
    new_bst.delete(10)
    assert new_bst.contains(10) is False
    assert new_bst.size == 2
    assert new_bst.head.value == 20
    assert new_bst.head.right is None
    assert new_bst.head.left.value == 5
開發者ID:jmcclena94,項目名稱:data-structures,代碼行數:15,代碼來源:test_bst.py

示例8: test_delete_on_small_range

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [as 別名]
def test_delete_on_small_range():
    """Test that the node selected is removed from the tree."""
    from bst import Bst
    new_bst = Bst()
    for items in range(5):
        new_bst.insert(items)
    new_bst.delete(1)
    assert new_bst.contains(1) is False
    assert new_bst.size == 4
    assert new_bst.head.value == 2
    assert new_bst.head.left.value == 0
    assert new_bst.head.right.value == 3
    assert new_bst.head.right.right.value == 4
開發者ID:jmcclena94,項目名稱:data-structures,代碼行數:15,代碼來源:test_bst.py

示例9: test_off_balance_delete_tree_non_head

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import delete [as 別名]
def test_off_balance_delete_tree_non_head():
    """Test deletion on tree from complex tree."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(10)
    new_bst.insert(20)
    new_bst.insert(5)
    new_bst.insert(15)
    new_bst.insert(25)
    new_bst.delete(20)
    assert new_bst.contains(20) is False
    assert new_bst.size == 4
    assert new_bst.head.value == 10
    assert new_bst.head.right.value == 25
    assert new_bst.head.left.value == 5
    assert new_bst.head.right.left.value == 15
開發者ID:jmcclena94,項目名稱:data-structures,代碼行數:18,代碼來源:test_bst.py


注:本文中的bst.Bst.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。