本文整理匯總了Python中bst.Bst.remove方法的典型用法代碼示例。如果您正苦於以下問題:Python Bst.remove方法的具體用法?Python Bst.remove怎麽用?Python Bst.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bst.Bst
的用法示例。
在下文中一共展示了Bst.remove方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_size
# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import remove [as 別名]
def test_size(self):
tree = Bst()
self.assertEquals(tree.size, 0)
self.assertEquals(tree.size, tree.getsize())
# Set tree size to arbitrary number
ARBITRARY_SIZE = 5
tree.size = ARBITRARY_SIZE
self.assertEquals(tree.size, ARBITRARY_SIZE)
self.assertEquals(tree.size, tree.getsize())
# Adding should increment size
tree = balanced_tree()
self.assertEquals(tree.getsize(), 7)
FAR_RIGHT_DATA = 100
tree.add(FAR_RIGHT_DATA)
self.assertEquals(tree.getsize(), 8)
# Removing should decrement size
tree = balanced_tree()
self.assertEquals(tree.getsize(), 7)
tree.remove(ROOT_DATA)
self.assertEquals(tree.getsize(), 6)
示例2: remove_one_child_root
# 需要導入模塊: from bst import Bst [as 別名]
# 或者: from bst.Bst import remove [as 別名]
def remove_one_child_root():
"""Removing root in a tree where the root has only one child"""
tree = Bst()
tree.add(ROOT_DATA)
tree.add(LEFT_DATA)
self.assertFalse(tree.isempty())
self.assertEquals(tree.getsize(), 2)
self.assertEquals(tree.root.getleft().getdata(), LEFT_DATA)
val = tree.remove(ROOT_DATA)
self.assertFalse(tree.isempty())
self.assertEquals(tree.getsize(), 1)
self.assertEquals(val, ROOT_DATA)
self.assertIsNotNone(tree.root)
self.assertNotEquals(tree.root.getdata(), ROOT_DATA)
self.assertEquals(tree.root, Node(LEFT_DATA))