本文整理匯總了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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