package com.geeks;

public class BinarySearchTree {
	public static void main(String[] args) {

	}

	private static class TreeNode<T> {
		TreeNode<T> left;
		TreeNode<T> right;

		T elem;
	}
}

@@ -13,16 +13,42 @@
 geeks;%0A%0A
+import java.util.Arrays;%0A%0A
 public c
@@ -113,16 +113,1736 @@
 args) %7B%0A
+%09%09Character%5B%5D inOrder = %7B 'D', 'B', 'E', 'A', 'F', 'C' %7D;%0A%09%09Character%5B%5D preOrder = %7B 'A', 'B', 'D', 'E', 'C', 'F' %7D;%0A%0A%09%09TreeNode%3CCharacter%3E tree = constructTreeNode(0, preOrder, inOrder);%0A%0A%09%09postOrderTraverse(tree, new TraverseCallback() %7B%0A%0A%09%09%09public %3CT%3E void callback(T t) %7B%0A%09%09%09%09TreeNode%3CCharacter%3E treeNode = (TreeNode%3CCharacter%3E) t;%0A%09%09%09%09System.out.println(treeNode.elem);%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D%0A%0A%09/**%0A%09 * %0A%09 * @param inOrder%0A%09 * @param preOrder%0A%09 * @return%0A%09 */%0A%09private static %3CT%3E TreeNode%3CT%3E constructTreeNode(int rootPos, T%5B%5D preOrder,%0A%09%09%09T%5B%5D inOrder) %7B%0A%09%09if (rootPos == preOrder.length) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%09if (inOrder == null %7C%7C inOrder.length == 0)%0A%09%09%09return null;%0A%0A%09%09T childRoot = preOrder%5BrootPos%5D;%0A%0A%09%09int i = 0;%0A%09%09for (; i %3C inOrder.length; i++) %7B%0A%09%09%09if (childRoot.equals(inOrder%5Bi%5D))%0A%09%09%09%09break;%0A%09%09%7D%0A%0A%09%09T%5B%5D leftChildInOrder = Arrays.copyOfRange(inOrder, 0, i);%0A%0A%09%09T%5B%5D rightChildInOrder = null;%0A%09%09if (i %3C inOrder.length - 1) %7B%0A%09%09%09rightChildInOrder = Arrays.copyOfRange(inOrder, i + 1,%0A%09%09%09%09%09inOrder.length);%0A%09%09%7D%0A%0A%09%09TreeNode%3CT%3E leftChild = constructTreeNode(rootPos + 1, preOrder,%0A%09%09%09%09leftChildInOrder);%0A%09%09TreeNode%3CT%3E rightChild = constructTreeNode(rootPos + i + 1, preOrder,%0A%09%09%09%09rightChildInOrder);%0A%0A%09%09TreeNode%3CT%3E node = new TreeNode%3CT%3E();%0A%09%09node.left = leftChild;%0A%09%09node.right = rightChild;%0A%09%09node.elem = childRoot;%0A%0A%09%09return node;%0A%09%7D%0A%0A%09private static %3CT%3E void postOrderTraverse(TreeNode%3CT%3E tree,%0A%09%09%09TraverseCallback callback) %7B%0A%09%09if (tree.right != null)%0A%09%09%09postOrderTraverse(tree.right, callback);%0A%0A%09%09if (tree.left != null)%0A%09%09%09postOrderTraverse(tree.left, callback);%0A%0A%09%09callback.callback(tree);%0A%09%09// System.out.println(tree.elem);%0A%09%7D%0A%0A%09private static interface TraverseCallback %7B%0A%09%09public %3CT%3E void callback(T t);
 %0A%09%7D%0A%0A%09pr

Add construct binary tree from inOrder and preOrder