本文整理汇总了Python中bst.BinarySearchTree.max方法的典型用法代码示例。如果您正苦于以下问题:Python BinarySearchTree.max方法的具体用法?Python BinarySearchTree.max怎么用?Python BinarySearchTree.max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.max方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_max
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import max [as 别名]
def test_max(self):
# 6
# / \
# 4 10
# \
# 16
bst = BinarySearchTree()
self.assertEqual(bst.max(), 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.max(), node_val4)
示例2: BinarySearchTree
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import max [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()))