package binaryTree.visitor; import binaryTree.*; /** * Replaces the root of the input tree with the minimum of the host, if any, * otherwise removes the input's root. */ public class RightDelDontAsk implements IVisitor { public final static RightDelDontAsk Singleton = new RightDelDontAsk (); private RightDelDontAsk() { } /** * Asks the input BiTree to remove its root. * @param host the right subtree of input. * @param input a BiTree with the binary search property. * @return */ public Object emptyCase(BiTree host, Object input) { ((BiTree)input).remRoot (); return null; } /** * Asks the input to set its root to the minimum value in the host, and removes * this minimum value from the host. * @param host the right subtree of input. * @param input a BiTree with the binary search property. * @return */ public Object nonEmptyCase(BiTree host, Object input) { BiTree parent = (BiTree)input; BiTree minTree = (BiTree)host.execute (MinTreeFinder.Singleton, null); Object min = minTree.getRootDat(); parent.setRootDat(min); minTree.execute (OOBSTDeleter.Singleton, min); return null; } }