本文整理汇总了Python中bst.BinarySearchTree.put方法的典型用法代码示例。如果您正苦于以下问题:Python BinarySearchTree.put方法的具体用法?Python BinarySearchTree.put怎么用?Python BinarySearchTree.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.put方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiple_element_put_init_empty
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import put [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')])
示例2: test_multiple_leaf
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import put [as 别名]
def test_multiple_leaf(self):
""" Tree of single item. """
a = BinarySearchTree()
a[7] = 'Harry'
a[8] = 'Ron'
a.put(4, 'Hermione')
a[9] = 'Ginny'
self.assertFalse(a._get(7, a.root).isLeaf())
示例3: test_multiple_element_get
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import put [as 别名]
def test_multiple_element_get(self):
""" Put mulitple items into an empty bst and test inorder. """
a = BinarySearchTree()
a.put(7, 'Harry')
a[8] = 'Ron'
a.put(4, 'Hermione')
a[9] = 'Ginny'
self.assertTrue(a[4] == 'Hermione')
示例4: test_simple_element_put
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import put [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')])
示例5: BinarySearchTree
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import put [as 别名]
from bst import BinarySearchTree
bst = BinarySearchTree()
bst.put('3', 'dog')
bst.put('8', 'pig')
bst.put('4', 'goat')
bst.put('2', 'lion')
bst.put('1', 'cat')
bst.put('5', "horse")
for item in bst:
print(item, bst[item])
print(bst.get('2'))
bst['2'] = 'rabbit'
print(bst['2'])
bst.delete('2')
try:
del bst['2']
except KeyError:
print("Not in the BST!")
#for item in bst:
# print(item)