本文整理汇总了Python中bst.BST.breadth_first方法的典型用法代码示例。如果您正苦于以下问题:Python BST.breadth_first方法的具体用法?Python BST.breadth_first怎么用?Python BST.breadth_first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BST
的用法示例。
在下文中一共展示了BST.breadth_first方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_breadth_first_traversal
# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import breadth_first [as 别名]
def test_breadth_first_traversal():
"""Tests breadth-first traversal"""
import types
bintree = BST()
with pytest.raises(TypeError):
bintree.breadth_first(1) # No args/kwargs
with pytest.raises(TypeError):
bintree.breadth_first(None)
assert isinstance(bintree.breadth_first(), types.GeneratorType)
bintree.insert(5)
bintree.insert(3)
bintree.insert(7)
bintree.insert(6)
bintree.insert(2)
bintree.insert(4)
bintree.insert(1)
bintree.insert(9)
bintree.insert(10)
# 5
# / \
# 3 7
# /\ / \
# 2 4 6 9
# | |
# 1 10
gen = bintree.breadth_first()
assert gen.next() == 5
assert gen.next() == 3
assert gen.next() == 7
assert gen.next() == 2
assert gen.next() == 4
assert gen.next() == 6
assert gen.next() == 9
assert gen.next() == 1
assert gen.next() == 10
with pytest.raises(StopIteration):
gen.next()