package binaryTree.visitor; import binaryTree.*; /** * Prints the binary tree host vertically. * @author Dung X. Nguyen */ public class VerticalPrinter implements IVisitor { /** @SBGen Singleton Variable */ public final static VerticalPrinter Singleton = new VerticalPrinter (); /** @SBGen Constructor */ private VerticalPrinter() { } /** * Prints [] on System.out and stays on the same line of output. * @param host * @param input not used. * @return null */ public Object emptyCase(BiTree host, Object input) { System.out.print ("[]"); return (null); } /** * Prints the host tree vertically on System.out and stays on the same line of output as the last printed tree node. * @param host * @param input an Integer indicating the level of the node. * @return null */ public Object nonEmptyCase(BiTree host, Object input) { return host.execute(VerticalPrintHelper.Singleton, new Integer (0)); } }