本文整理汇总了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')
示例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')])
示例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')])
示例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')])
示例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() == [])
示例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')])
示例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')])
示例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')])
示例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() == [])
示例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')])