本文整理汇总了Python中bst.BinarySearchTree.min方法的典型用法代码示例。如果您正苦于以下问题:Python BinarySearchTree.min方法的具体用法?Python BinarySearchTree.min怎么用?Python BinarySearchTree.min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.min方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iterator
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import min [as 别名]
def test_iterator(self):
bst = BinarySearchTree()
self.assertEqual(bst.min(), None)
node_val1 = 6
bst.add(node_val1)
node_val2 = 4
bst.add(node_val2)
node_val3 = 10
bst.add(node_val3)
node_val4 = 16
bst.add(node_val4)
# 6
# / \
# 4 10
# \
# 16
ite = BinarySearchIterator(bst)
self.assertEquals(ite.tree, bst)
self.assertEquals(ite.next(), 4)
self.assertEquals(ite.next(), 6)
self.assertEquals(ite.next(), 10)
self.assertEquals(ite.next(), 16)
self.assertRaises(StopIteration, ite.next)
示例2: test_print_node
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import min [as 别名]
def test_print_node(self):
bst = BinarySearchTree()
self.assertEqual(bst.min(), None)
node_val1 = 6
bst.add(node_val1)
node_val2 = 4
bst.add(node_val2)
node_val3 = 10
bst.add(node_val3)
node_val4 = 16
bst.add(node_val4)
# 6
# / \
# 4 10
# \
# 16
#self.assertEqual(bst.__str__(), "4 6 10")
self.assertEqual(bst.root_node.__str__(), "4 6 10")
self.assertEqual(bst.root_node.right_child.__str__(), "10 16")
self.assertEqual(bst.root_node.right_child.right_child.__str__(), "16")
示例3: test_is_search_tree
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import min [as 别名]
def test_is_search_tree(self):
# No assertion here, I just want a beautifully designed tree.
bst = BinarySearchTree()
self.assertEqual(bst.min(), None)
node_val1 = 6
bst.add(node_val1)
node_val2 = 4
bst.add(node_val2)
node_val3 = 10
bst.add(node_val3)
node_val4 = 16
bst.add(node_val4)
# 6
# / \
# 4 10
# \
# 16
self.assertTrue(BinarySearchTree.is_search_tree(bst.root_node))
# 6
# / \
# 8 10
# \
# 16
bst.root_node.left_child.value = 8
self.assertEqual(bst.root_node.left_child.value, 8)
self.assertFalse(BinarySearchTree.is_search_tree(bst.root_node))
# 12
# / \
# 4 10
# \
# 16
bst.root_node.left_child.value = 4
self.assertEqual(bst.root_node.left_child.value, 4)
bst.root_node.value = 12
self.assertEqual(bst.root_node.value, 12)
self.assertFalse(BinarySearchTree.is_search_tree(bst.root_node))
# 6
# / \
# 4 20
# \
# 16
bst.root_node.left_child.value = 6
self.assertEqual(bst.root_node.left_child.value, 6)
bst.root_node.right_child.value = 20
self.assertEqual(bst.root_node.right_child.value, 20)
self.assertFalse(BinarySearchTree.is_search_tree(bst.root_node))
示例4: test_min
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import min [as 别名]
def test_min(self):
# 6
# / \
# 4 10
# \
# 16
bst = BinarySearchTree()
self.assertEqual(bst.min(), None)
node_val1 = 6
bst.add(node_val1)
node_val2 = 4
bst.add(node_val2)
node_val3 = 10
bst.add(node_val3)
node_val4 = 16
bst.add(node_val4)
self.assertEqual(bst.size, 4)
self.assertEqual(bst.min(), node_val2)
示例5: test_print_tree
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import min [as 别名]
def test_print_tree(self):
bst = BinarySearchTree()
self.assertEqual(bst.min(), None)
node_val1 = 6
bst.add(node_val1)
node_val2 = 4
bst.add(node_val2)
node_val3 = 10
bst.add(node_val3)
node_val4 = 16
bst.add(node_val4)
# 6
# / \
# 4 10
# \
# 16
self.assertEqual(bst.__str__(), "4 6 10 16")
示例6: test_is_search_node
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import min [as 别名]
def test_is_search_node(self):
bst = BinarySearchTree()
self.assertEqual(bst.min(), None)
# 6
# / \
# 4 10
# \
# 16
node_val1 = 6
bst.add(node_val1)
node_val2 = 4
bst.add(node_val2)
node_val3 = 10
bst.add(node_val3)
node_val4 = 16
bst.add(node_val4)
self.assertTrue(BinarySearchTree.is_search_node(bst.root_node))
self.assertTrue(BinarySearchTree.is_search_node(bst.root_node.left_child))
self.assertTrue(BinarySearchTree.is_search_node(bst.root_node.right_child))
self.assertTrue(BinarySearchTree.is_search_node(None))
示例7: BinarySearchTree
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import min [as 别名]
"""
ASTR 598 HW 7
Brett Morris
"""
from __future__ import print_function # Python 2 compatibility
from bst import BinarySearchTree
# Generate some random integers:
import numpy as np
integers = np.random.randint(0, 1000, size=100).tolist()
bst = BinarySearchTree()
# Insert some random integers into the binary search tree:
for integer in integers:
bst.insert(integer)
# Traverse that tree in order (notice they're in order, wahoo!)
print("Traverse:")
bst.traverse()
# Find min, max:
print("Min: {0}, max: {1}".format(bst.min(), bst.max()))