package brsVisitor; import brs.*; /** * This IBRSAlgo will find the maximum depth of a BiTree. The depth of an empty tree is zero. The depth of a single element tree is one. */ public class BRSGetMaxDepthVisitor implements IVisitor { /** * Returns an Integer object of value 0 * @param host The BiTree host * @param param not used. * @return Integer(0) always */ public Object emptyCase(BiTree host, Object input) { return( new Integer(0)); } /** * Recursively calculates the maximum depth of the tree. * @param host The BiTree host * @param param not used. * @return An Integer object */ public final Object nonEmptyCase(BiTree host, Object input) { int nr = ((Integer)(host.getRightSubTree()).execute(this, input)).intValue(); int nl = ((Integer)(host.getLeftSubTree()).execute(this, input)).intValue(); return ((nr>nl) ? new Integer(++nr) : new Integer(++nl)); } }