Build a binary Tree from inOrder and preOrder data in Java -
i've gone through program few times, can't see issue. basically, supposed reconstruct binary tree inorder , preorder traversal data (sent in integer arrays) it's binary tree of integers. here's tree i'm using: 234 / \ 98 678 / \ \ 45 124 1789 preorder 234, 98, 45, 124, 678, 1789 inorder 45, 98, 124, 234, 678, 1789 the problem comes 1789. code reconstructs tree 1789, leaving out odd reason. decided switch 678 , 1789 in inorder array, , put 1789 left of 678, , 0 right of 678. in code below, arrays in order supposed (or assume supposed be). build tree code: public class buildtree { public static binarytreenode buildtree(int inorder[], int preorder[], int preindex ) { if (inorder.length > 1) { int inindex = 0; (int = 0; < inorder.length; i++) { if (preorder[preindex] == inorder[i]) { inindex = ; break;