當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。