当前位置: 首页>>代码示例>>Python>>正文


Python Bst.head方法代码示例

本文整理汇总了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
开发者ID:jmcclena94,项目名称:data-structures,代码行数:29,代码来源:test_bst.py

示例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
开发者ID:jmcclena94,项目名称:data-structures,代码行数:19,代码来源:test_bst.py

示例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
开发者ID:jmcclena94,项目名称:data-structures,代码行数:21,代码来源:test_bst.py


注:本文中的bst.Bst.head方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。