public class Tree { // the root of the tree private TreeNode root; //empty tree public Tree(){ } // rootItem, empty children public Tree(TreeNode root){ } public boolean isEmpty(){ return true; } public void preorderTraverse(){ if (!isEmpty()) preorderTraverse(root,""); else System.out.println("null"); } // print root item // print left tree // print right tree public void preorderTraverse(TreeNode node, String indent){ System.out.println(indent+node.getItem()); if(node.getLeft()!=null) preorderTraverse(node.getLeft(),indent+" "); if(node.getRight()!=null) preorderTraverse(node.getRight(),indent+" "); } // if tree empty return null // else evaluate the tree by postorder traversal // and return its value public Boolean postorderEval(){ Boolean res = null; if(!isEmpty()){ res = postorderEval(root); } return res; } // evaluate left tree // evaluate right tree (if not null) // evaluate node and return Boolean result public Boolean postorderEval(TreeNode node){ String item = node.getItem(); return false; } public static void main(String[] args){ args = Debug.init(args); System.out.println("Testing Tree and TreeNode"); System.out.println("Stepwise build infix expression:\n not not (true or false) and true"); Tree t = new Tree(); System.out.println("\ntree: "); t.preorderTraverse(); System.out.println("result: " + t.postorderEval()); TreeNode a = new TreeNode("true"); t = new Tree(a); System.out.println("\ntree: "); t.preorderTraverse(); System.out.println("result: " + t.postorderEval()); TreeNode b = new TreeNode("false"); TreeNode or = new TreeNode("or", a, b); t = new Tree(or); System.out.println("\ntree: "); t.preorderTraverse(); System.out.println("result: " + t.postorderEval()); TreeNode not2 = new TreeNode("not", or); t = new Tree(not2); System.out.println("\ntree: "); t.preorderTraverse(); System.out.println("result: " + t.postorderEval()); TreeNode not = new TreeNode("not", not2); TreeNode and = new TreeNode("and", not, new TreeNode("true")); t = new Tree(and); System.out.println("\ntree: "); t.preorderTraverse(); System.out.println("result: " + t.postorderEval()); } }