当前位置: 首页>>代码示例>>Python>>正文


Python BinarySearchTree.min方法代码示例

本文整理汇总了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)
开发者ID:imclab,项目名称:Coding4Interviews,代码行数:32,代码来源:bst_test.py

示例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")
开发者ID:imclab,项目名称:Coding4Interviews,代码行数:27,代码来源:bst_test.py

示例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))
开发者ID:imclab,项目名称:Coding4Interviews,代码行数:55,代码来源:bst_test.py

示例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)
开发者ID:imclab,项目名称:Coding4Interviews,代码行数:25,代码来源:bst_test.py

示例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")
开发者ID:imclab,项目名称:Coding4Interviews,代码行数:23,代码来源:bst_test.py

示例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))
开发者ID:imclab,项目名称:Coding4Interviews,代码行数:26,代码来源:bst_test.py

示例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()))
开发者ID:bmorris3,项目名称:astr598,代码行数:26,代码来源:myprogram.py


注:本文中的bst.BinarySearchTree.min方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。