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


Python BinarySearchTree.inorder方法代码示例

本文整理汇总了Python中bst.BinarySearchTree.inorder方法的典型用法代码示例。如果您正苦于以下问题:Python BinarySearchTree.inorder方法的具体用法?Python BinarySearchTree.inorder怎么用?Python BinarySearchTree.inorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bst.BinarySearchTree的用法示例。


在下文中一共展示了BinarySearchTree.inorder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_nonleaf_delete

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
    def test_nonleaf_delete(self):
        """ Try to delete non leaf node with both children. """
        a = BinarySearchTree(7, 'Harry')
        a[8] = 'Ron'
        a[5] = 'Ginny'
        a[4] = 'Hermione'
        a[6] = 'Neville'

        """                     7 - Harry
                             /             \  
                       5- Ginny           8 - Ron
                       /      \  
                4-Hermione    6-Neville
        """

        a.delete(7)
        self.assertTrue(a.inorder() == [(4, 'Hermione'), (5, 'Ginny'), (6, 'Neville'), (8, 'Ron')])
        self.assertTrue(a.root.value == 'Neville')

        a[7] = 'Harry'
        self.assertTrue(a.inorder() == [(4, 'Hermione'), (5, 'Ginny'), (6, 'Neville'), (7, 'Harry'), (8, 'Ron')])

        a.delete(6)
        self.assertTrue(a.inorder() == [(4, 'Hermione'), (5, 'Ginny'), (7, 'Harry'), (8, 'Ron')])
        self.assertTrue(a.root.value == 'Ginny')
开发者ID:soldatfer,项目名称:bst,代码行数:27,代码来源:test.py

示例2: test_leaf_delete

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
 def test_leaf_delete(self):
     """ Try to delete leaf nodes. """
     a = BinarySearchTree(7, 'Harry')
     a[8] = 'Ron'
     a[9] = 'Ginny'
     a[4] = 'Hermione'
     self.assertTrue(a.inorder() == [(4, 'Hermione'), (7, 'Harry'), (8, 'Ron'), (9, 'Ginny')])
     a.delete(9)
     self.assertTrue(a.inorder() == [(4, 'Hermione'), (7, 'Harry'), (8, 'Ron')])
     a.delete(4)
     self.assertTrue(a.inorder() == [(7, 'Harry'), (8, 'Ron')])
     a.delete(8)
     self.assertTrue(a.inorder() == [(7, 'Harry')])
开发者ID:soldatfer,项目名称:bst,代码行数:15,代码来源:test.py

示例3: test_multiple_element_put_init_empty

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
    def test_multiple_element_put_init_empty(self):
        """ Put mulitple items into an empty bst and test inorder. """
	a = BinarySearchTree()
	a.put(7, 'Harry')
	a[8] = 'Ron'
	a.put(4, 'Hermione')
        self.assertTrue(a.inorder() == [(4, 'Hermione'), (7, 'Harry'), (8, 'Ron')])
开发者ID:soldatfer,项目名称:bst,代码行数:9,代码来源:test.py

示例4: test_nonleaf_rightnone_delete

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
 def test_nonleaf_rightnone_delete(self):
     """ Try to delete non leaf node with no right child. """
     a = BinarySearchTree(7, 'Harry')
     a[8] = 'Ron'
     a[5] = 'Ginny'
     a[4] = 'Hermione'
     a.delete(5)
     self.assertTrue(a.inorder() == [(4, 'Hermione'), (7, 'Harry'), (8, 'Ron')])
开发者ID:soldatfer,项目名称:bst,代码行数:10,代码来源:test.py

示例5: test_empty_bst

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
 def test_empty_bst(self):
     """ Simple bst init should return [] on traversal. """
     a = BinarySearchTree()
     self.assertTrue(a.inorder() == [])
开发者ID:soldatfer,项目名称:bst,代码行数:6,代码来源:test.py

示例6: test_simple_element_setitem

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
    def test_simple_element_setitem(self):
        """ Setitem simple element and test status. """
	a = BinarySearchTree()
	a[7] = 'Harry'
        self.assertTrue(a.inorder() == [(7, 'Harry')])
开发者ID:soldatfer,项目名称:bst,代码行数:7,代码来源:test.py

示例7: test_simple_element_put

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
    def test_simple_element_put(self):
        """ Insert simple element and test status. """
	a = BinarySearchTree()
	a.put(7, 'Harry')
        self.assertTrue(a.inorder() == [(7, 'Harry')])
开发者ID:soldatfer,项目名称:bst,代码行数:7,代码来源:test.py

示例8: test_single_element_bst_init_int_str

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
 def test_single_element_bst_init_int_str(self):
     """ Inorder rep of a bst init with a single item with int key and str value. """
     a = BinarySearchTree(7, 'Harry')
     self.assertTrue(a.inorder() == [(7, 'Harry')])
开发者ID:soldatfer,项目名称:bst,代码行数:6,代码来源:test.py

示例9: test_root_delete

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
    def test_root_delete(self):
        """ Try to delete the root in a single element tree. """
        a = BinarySearchTree(7, 'Harry')
	a.delete(7)
	self.assertTrue(a.inorder() == [])
开发者ID:soldatfer,项目名称:bst,代码行数:7,代码来源:test.py

示例10: test_non_existing_delete

# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import inorder [as 别名]
    def test_non_existing_delete(self):
        """ Try to delete a non existant item. """
        a = BinarySearchTree(7, 'Harry')
	a.delete(8)
	self.assertTrue(a.inorder() == [(7, 'Harry')])
开发者ID:soldatfer,项目名称:bst,代码行数:7,代码来源:test.py


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