package binaryTree.visitor; import binaryTree.*; /** * Returns the leftmost non-empty subtree of the host. */ public class LeftmostTreeFinder implements IAlgo { public final static LeftmostTreeFinder Singleton = new LeftmostTreeFinder(); private LeftmostTreeFinder() { } /** * @param * @param * @return */ public Object emptyCase(BiTree host, Object input) { throw new IllegalArgumentException("The host is an empty tree."); } /** * @param host * @param input * @return */ public Object nonEmptyCase(BiTree host, Object input) { return host.getLeftSubTree().execute(new IAlgo() { public Object emptyCase(BiTree host, Object input) { return input; } public Object nonEmptyCase(BiTree host, Object input) { return host.getLeftSubTree().execute(this, host); } }, host); } }