public void in(Node head){
if(head != null){
Stack<Node> stack = new Stack<>();
while(!stack.isEmpty() || head != null){
if(head != null){
stack.push(head);
head = head.left;
}else{
head = stack.pop();
System.out.print(head.value + " ");
head = head.right;
}
}
}
System.out.println();
}
思路:1.整条左边界依次压入栈
2.1无法执行就弹出然后打印,然后来到弹出结点的右树执行1.
每课子树整棵树左边界进栈
依次弹的过程中打印
对弹出节点的有树重复进行以上操作
这样每次都是左头右,然后这个右树也左头右