1.前序遍历
public void preorder(Visitor<E> visitor) {
if (visitor == null || visitor == null) return;
Node<E> node = root;
LinkedList<Node<E>> stack = new LinkedList<>();
while (true) {
if (node != null) {
visitor.visit(node.element);
if (node.right != null) {
stack.push(node.right);
}
node = node.left;
} else {
if (!stack.isEmpty()) {
node = stack.pop();
} else {
return;
}
}
}
}
2.中序遍历
3.后序遍历