|
>>> tree = Tree(5,
... [Tree(4, [Tree(2, [1, 3])]),
... Tree(8, [Tree(6, [7]), 9])])
>>> for x in breadth_first(tree):
... if isinstance(x, int): print(x)
... else: print(x.label())
5
4
8
2
6
9
1
3
7
>>> for x in breadth_first(tree, maxdepth=2):
... if isinstance(x, int): print(x)
... else: print(x.label())
5
4
8
2
6
9
|