在 Python 3 中,
class BinaryTree:
"""
=== Private Attributes ===
@type _root: object | None
@type _left: BinaryTree | None
@type _right: BinaryTree | None
"""
def __init__(self, root, left, right):
if root is None:
# store an empty BinaryTree
self._root = None
self._left = None
self._right = None
else:
self._root = root
self._left = left
self._right = right
def is_empty(self):
return self._root is None
我知道如何使用递归遍历这个二叉树,但我想知道如何不使用递归来进行遍历。