先根遍历,中根遍历,后根遍历 二叉树并且 循环+递归两种方式
public class BinaryTreeNode {
private int value;
public BinaryTreeNode leftNode;
public BinaryTreeNode rightNode;
public void setValue(int v){
this.value = v;
}
public int getValue(){
return this.value;
}
}
public class BinaryTree {
public static BinaryTreeNode treeRoot;
static{
treeRoot = new BinaryTreeNode();
treeRoot.setValue(1);
treeRoot.leftNode = new BinaryTreeNode();
treeRoot.leftNode.setValue(2);
treeRoot.rightNode = new BinaryTreeNode();
treeRoot.rightNode.setValue(3);
treeRoot.leftNode.leftNode = new BinaryTreeNode();
treeRoot.leftNode.leftNode.setValue(4);
treeRoot.leftNode.rightNode = new BinaryTreeNode();
treeRoot.leftNode.rightNode.setValue(5);
treeRoot.rightNode.leftNode = new BinaryTreeNode();
treeRoot.rightNode.leftNode.setValue(6);
treeRoot.rightNode.rightNode = new BinaryTreeNode();
treeRoot.rightNode.rightNode.setValue(7);
}
}
package Chapter2;
public class BinaryTreeNodeCode{