解答
中序遍历的操作如下:
1)中序遍历左子树;
2)访问根节点;
3)中序遍历右子树;
public void inOrder() {
Node current = root;
//把LinkedList作为栈使用
LinkedList<Node> s = new LinkedList<Node>();
while (current != null || !s.isEmpty()) {
while (current != null) {
s.addFirst(current);
current = current.left;
}
if (!s.isEmpty()) {
current = s.removeFirst();
System.out.print(current.data + " -> ");
current = current.right;
}
}
}
帖子还没人回复快来抢沙发