import structure.*; import com.mw.io.*; public class BTBuilder { public static void display (BinaryTreeNode root) { if (root != null) { display(root.left()); display(root.right()); System.out.print(root.value() + " "); } } public static void main (String args[]) { ReadStream r = new ReadStream(); String S; BinaryTreeNode t, U, V; Stack T = new StackList(); // read data from input and build the tree S = r.readString(); while (!r.eof()) { t = new BinaryTreeNode(S); if (S.equals("+") || S.equals("-") || S.equals("*") || S.equals("/")) { U = (BinaryTreeNode)T.pop(); V = (BinaryTreeNode)T.pop(); t.setLeft(V); t.setRight(U); T.push(t); } else T.push(t); S = r.readString(); } // pop and display the final tree on the stack display((BinaryTreeNode)T.pop()); System.out.println("\nend of run"); } }