本文整理汇总了Python中bst.Bst.head方法的典型用法代码示例。如果您正苦于以下问题:Python Bst.head方法的具体用法?Python Bst.head怎么用?Python Bst.head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.Bst
的用法示例。
在下文中一共展示了Bst.head方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_right_left_conversion_six_nodes
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import head [as 别名]
def test_right_left_conversion_six_nodes():
"""
Test that given six nodes in a left-right state converts to left-left.
"""
from bst import Bst, Node
new_bst = Bst()
node1 = Node(10)
node2 = Node(5)
node3 = Node(15)
node4 = Node(20)
node5 = Node(14)
node6 = Node(13)
new_bst.head = node1
node1.left = node2
node2.parent = node1
node1.right = node3
node3.parent = node1
node3.right = node4
node4.parent = node3
node3.left = node5
node5.parent = node3
node5.left = node6
node6.parent = node5
new_bst.head.right_left_conversion()
assert new_bst.head.right == node5
assert new_bst.head.right.right == node3
assert new_bst.head.right.right.right == node4
示例2: test_left_rotation_three_nodes
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import head [as 别名]
def test_left_rotation_three_nodes():
"""Test that a right-right becomes balanced."""
from bst import Bst, Node
new_bst = Bst()
node1 = Node(10)
node2 = Node(15)
node3 = Node(20)
new_bst.head = node1
node1.right = node2
node2.parent = node1
node2.right = node3
node3.parent = node2
new_bst.head.left_rotation()
assert node2.parent is None
assert node2.left == node1
assert node2.right == node3
assert node2.left.parent == node2
示例3: test_right_left_conversion_three_nodes
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import head [as 别名]
def test_right_left_conversion_three_nodes():
"""
Test that given three nodes in a right-left state converts to right-right.
"""
from bst import Bst, Node
new_bst = Bst()
node1 = Node(10)
node2 = Node(15)
node3 = Node(12)
new_bst.head = node1
node1.right = node2
node2.parent = node1
node2.left = node3
node3.parent = node2
new_bst.head.right_left_conversion()
assert new_bst.head.right == node3
assert new_bst.head.right.right == node2
assert new_bst.head.right.right.parent == node3
assert new_bst.head.right.parent == node1