//中叙遍历的非递归实现---利用栈
public void inOrder(TreeNode root){
Stack<TreeNode> stack = new Stack<TreeNode>();
TreeNode p = root;
while (p!=null || !stack.isEmpty()) {
while (p!=null) {
stack.push(p);
p=p.left;
}
if (!stack.isEmpty()) {
p=stack.pop();
System.out.println(p.val);
p=p.right;
}
}
}
public void inOrder(TreeNode root){
Stack<TreeNode> stack = new Stack<TreeNode>();
TreeNode p = root;
while (p!=null || !stack.isEmpty()) {
while (p!=null) {
stack.push(p);
p=p.left;
}
if (!stack.isEmpty()) {
p=stack.pop();
System.out.println(p.val);
p=p.right;
}
}
}