根据前序遍历和中序遍历重建二叉树
package com.study; /* * 根据二叉树的前序遍历和中序遍历结果重建二叉树 * 并输出其头节点。假设前序遍历和中序遍历结果中没有重复数字 * 前序遍历序列:{1,2,4,7,3,5,6,8} * 中序遍历序列:{4,7,2,1,5,3,8,6} * **/ class TreeNode { public int data; public TreeNode left; public TreeNode right; public TreeNode() { } } public class suanfa4 { private static int[] arr1 = {1,2,4,7,3,5,6,8}; private static int[] arr2 = {4,7,2,1,5,3,8,6}; public static TreeNode RebuildBinaryTree() { TreeNode head = null; head = ConstructBTree( head ,arr1, 0, 7, arr2, 0, 7); return head; } public static TreeNode ConstructBTree(TreeNode node, int[] pre, int pre_start, int pre_end, int[] inorder,