代码如下:
package binaryArithmeticTree;
/**
* 用链表实现二叉运算树
*/
public class BinaryArithmeticTree {
/**
*
* @author:孙创
* @date:2017年3月13日
* @Discription:节点类的声明
*/
class TreeNode {
TreeNode leftNode;
TreeNode rightNode;
int value;
public TreeNode(int value) {
this.value = value;
leftNode = null;
rightNode = null;
}
}
/**
*
* @author:孙创
* @date:2017年3月13日
* @Discription:二叉搜索树类的声明,即建立一个二叉树的方法(链表法)。
*/
class BuildBinaryTree {
public TreeNode rootNode;// 二叉树的根节点
// 构造函数:建立空的二叉树
public BuildBinaryTree() {
this.rootNode = null;
}
// 构造函数:通过传入一个数组建立二叉树
public BuildBinaryTree(int[] data) {
for (int i = 0; i < data.length; i++) {
AddNodeToTree(data[i]);
}
}
/**
* 将指定的值加入到二叉树中适合的节点处
*
* @param value
*/