package binaryTree.visitor; import binaryTree.BiTree; /** * Returns the subtree of the host with the min value in the root if the tree is not empty, otherwise returns the host itself. */ public class MinTreeFinder implements IVisitor { /** @SBGen Singleton Variable */ public final static MinTreeFinder Singleton = new MinTreeFinder (); /** @SBGen Constructor */ private MinTreeFinder() { } /** * @param host satisfies the binary search tree property. * @param input == null, not used. * @return host */ public Object nullCase(BiTree host, Object input) { return host; } /** * @param host satisfies the binary search tree property. * @param input == null, not used. * @return subtree with minimum root. */ public Object nonNullCase(BiTree host, Object input) { Boolean isLeftEmpty = (Boolean)host.getLeftSubTree().execute (EmptyChecker.Singleton, null); return isLeftEmpty.booleanValue()? host: host.getLeftSubTree ().execute (this, null); } }