LeftDeleter.java
Created with JBuilder

package brs.visitor;

import brs.*;
import ordering.*;

/**
* Removes the root of the host's parent. The host's parent and the calling
* deletion algorithm are passed to this IVisitor in the constructor.
*/
public class LeftDeleter implements IVisitor {
    /**
    * The parent of the host.
    */
    private BiTree _hostParent;

    /**
    * The BSTDeleter algorithm that calls this IVisitor.
    */
    private IVisitor _deleter;

    public LeftDeleter (BiTree parent, IVisitor del) {
        _hostParent = parent;
        _deleter = del;
    }

    /**
    * Asks the _hostParent's right subtree to help delete _hostParent's root.
    * @param host the left subtree of _hostParent.
    * @param input not used
    * @return null.
    */
    public Object emptyCase (BiTree host, Object input) {
        return _hostParent.getRightSubTree().
                    execute(new RightDelDontAsk(_hostParent, _deleter), null);
    // EXERCISE: Replace RightDelDontAsk with an anonymous inner class.
    }

    /**
    * Finds the maximum value in the host.
    * Asks the _hostParent to set its root to this maximum value, and removes
    * this maximum value from the host.
    * @param host the left subtree of _hostParent.
    * @param input not used.
    * @return null.
    */
    public Object nonEmptyCase (BiTree host, Object input) {
        BiTree maxTree = (BiTree)host.execute(MaxTreeFinder.Singleton, null);
        Object max = maxTree.getRootDat();
        _hostParent.setRootDat(max);
        maxTree.execute(_deleter, max);
        return null;
    }
}



LeftDeleter.java
Created with JBuilder