本文整理汇总了Python中Node.Node.key方法的典型用法代码示例。如果您正苦于以下问题:Python Node.key方法的具体用法?Python Node.key怎么用?Python Node.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.key方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import key [as 别名]
def test_delete():
bs_tree = BinarySearchTree()
keys = [5, 2, -4, 3, 12, 9 ,21, 19, 25]
for key in keys:
node = Node()
node.key = key
bs_tree.insert(node)
# delete leaf
bs_tree.delete(bs_tree.search(-4))
assert(bs_tree.search(-4) is None)
assert(bs_tree.search(2).left is None)
# delete node with one child
bs_tree.delete(bs_tree.search(2))
assert(bs_tree.search(2) is None)
assert(bs_tree.root.left.key == 3)
# delete node with two children
bs_tree.delete(bs_tree.search(12))
assert(bs_tree.root.right.key == 19)
assert(bs_tree.search(19).left.key == 9)
assert(bs_tree.search(19).right.key == 21)
# delete root
bs_tree.delete(bs_tree.root)
assert(bs_tree.root.key == 9)
assert(bs_tree.root.left.key == 3)
assert(bs_tree.root.right.key == 19)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:33,代码来源:BinarySearchTree_test.py
示例2: test_insert
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import key [as 别名]
def test_insert():
bs_tree = BinarySearchTree()
keys = [6, 5, 7, 2, 5, 8]
for key in keys:
node = Node()
node.key = key
bs_tree.insert(node)
assert(bs_tree.search(6).key == 6)
assert(bs_tree.search(5).key == 5)
assert(bs_tree.search(7).key == 7)
assert(bs_tree.search(8).key == 8)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:13,代码来源:BinarySearchTree_test.py
示例3: test_maximum
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import key [as 别名]
def test_maximum():
bs_tree = BinarySearchTree()
assert(bs_tree.minimum(bs_tree.root) is None)
keys = [6, 5, 7, 2, 5, 8]
for key in keys:
node = Node()
node.key = key
bs_tree.insert(node)
assert(bs_tree.maximum(bs_tree.root).key == 8)
subtree = bs_tree.search(5)
assert(bs_tree.maximum(subtree).key == 5)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:13,代码来源:BinarySearchTree_test.py
示例4: test_search
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import key [as 别名]
def test_search():
bs_tree = BinarySearchTree()
assert(bs_tree.search(2) is None)
keys = [6, 5, 7, 2]
for key in keys:
node = Node()
node.key = key
bs_tree.insert(node)
assert(bs_tree.search(6).key == 6)
assert(bs_tree.search(7).key == 7)
assert(bs_tree.search(8) is None)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:13,代码来源:BinarySearchTree_test.py
示例5: test_predecessor
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import key [as 别名]
def test_predecessor():
bs_tree = BinarySearchTree()
keys = [6, 5, 7, 2, 5, 8]
for key in keys:
node = Node()
node.key = key
bs_tree.insert(node)
assert(bs_tree.predecessor(bs_tree.root).key == 5)
subtree = bs_tree.search(7)
assert(bs_tree.predecessor(subtree).key == 6)
subtree = bs_tree.search(2)
assert(bs_tree.predecessor(subtree) is None)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:14,代码来源:BinarySearchTree_test.py