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


Python Bst.balance方法代碼示例

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


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

示例1: test_balance_left_two_nodes

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

示例2: test_balance_right_two_nodes

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

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

示例4: test_balance_equal

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

示例5: test_balance_equal_complex

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import balance [as 別名]
def test_balance_equal_complex():
    """Test a balanced list with multiple nodes."""
    from bst import Bst
    r1 = range(5, 0, -1)
    new_bst = Bst()
    for i in r1:
        new_bst.insert(i)
    r2 = range(10, 14)
    for i in r2:
        new_bst.insert(i)
    assert new_bst.balance() == 0
開發者ID:cacizi41,項目名稱:data-structures,代碼行數:13,代碼來源:test_bst.py

示例6: test_balance_left_complex

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import balance [as 別名]
def test_balance_left_complex():
    """Test a left heavy list with multiple nodes."""
    from bst import Bst
    r = range(4, -1, -1)
    new_bst = Bst()
    for i in r:
        new_bst.insert(i)
    assert new_bst.balance() == 1
    assert new_bst.head.value == 3
    assert new_bst.head.right.value == 4
    assert new_bst.head.left.value == 1
    assert new_bst.head.left.right.value == 2
    assert new_bst.head.left.left.value == 0
開發者ID:jmcclena94,項目名稱:data-structures,代碼行數:15,代碼來源:test_bst.py

示例7: test_balance_equal_complex

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import balance [as 別名]
def test_balance_equal_complex():
    """Test a balanced list with multiple nodes."""
    from bst import Bst
    r1 = range(5, 0, -1)
    new_bst = Bst()
    for i in r1:
        new_bst.insert(i)
    r2 = range(10, 14)
    for i in r2:
        new_bst.insert(i)
    assert new_bst.balance() == -1
    assert new_bst.head.value == 4
    assert new_bst.head.right.value == 10
    assert new_bst.head.right.left.value == 5
    assert new_bst.head.right.right.value == 12
    assert new_bst.head.right.right.left.value == 11
    assert new_bst.head.right.right.right.value == 13
    assert new_bst.head.left.value == 2
    assert new_bst.head.left.left.value == 1
    assert new_bst.head.left.right.value == 3
開發者ID:jmcclena94,項目名稱:data-structures,代碼行數:22,代碼來源:test_bst.py

示例8: test_balance_empty_list

# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import balance [as 別名]
def test_balance_empty_list():
    """Test returns 0 if tree is empty."""
    from bst import Bst
    new_bst = Bst()
    assert new_bst.balance() == 0
開發者ID:cacizi41,項目名稱:data-structures,代碼行數:7,代碼來源:test_bst.py


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