本文整理汇总了Python中bst.BST._find_minimum_and_delete方法的典型用法代码示例。如果您正苦于以下问题:Python BST._find_minimum_and_delete方法的具体用法?Python BST._find_minimum_and_delete怎么用?Python BST._find_minimum_and_delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BST
的用法示例。
在下文中一共展示了BST._find_minimum_and_delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_minimum_and_delete
# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import _find_minimum_and_delete [as 别名]
def test_find_minimum_and_delete():
"""Should return the minimum value in a (sub)tree and delete that leaf"""
bintree = BST()
bintree.insert(5)
bintree.insert(3)
bintree.insert(7)
bintree.insert(2)
bintree.insert(4)
bintree.insert(1)
bintree.insert(9)
bintree.insert(10)
# 5
# / \
# 3 7
# /\ \
# 2 4 9
# | |
# 1 10
assert bintree.size() == 8
assert bintree._find_minimum_and_delete() == 1
# 5
# / \
# 3 7
# /\ \
# 2 4 9
# |
# 10
assert bintree.size() == 7
bintree.rightchild._find_minimum_and_delete() == 7
# The "head" of the right subtree is deleted in this case
# 5
# / \
# 3 9
# /\ \
# 2 4 10
assert bintree.size() == 6
assert bintree.rightchild.value == 9