//二叉树中序遍历
public class Node{
public int value;
public Node left;
public Node right;
public Node(int data){
this.value=data;
}
}
//递归实现二叉树中序遍历
public void inOrderRecur(Node head){
if(head==null){
return;
}
System.out.println(head.value + " ");
inOrderRecur(head.left);
inOrderRecur(head.right);
}
//非递归实现二叉树中序遍历
public void inOrderUnRecur(Node head){
System.out.println("in-order: ");
if(head!=null){
Stack<Node> stack=new Stack<Node>();
while(!stack.isEmpty()||head!=null){
if(head!=null){
stack.push(head);
head=head.left;
}else{
head=stack.pop();
System.out.println(head.value + " ");
head=head.right;
}
}
}
System.out.println();
}