
/**
 * HeightVisitor.java
 *
 *
 * Created: Thu Oct 17 17:40:56 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */

public class HeightVisitor implements Visitor{
   public HeightVisitor (){
      
   }
   
   public Object operation(Object obt, Object inp)
   {  
      BTree bt = (BTree) obt;
      
      // base case: leaf
       if ( (bt.getLeft()==null)&& (bt.getRight()==null) ) {
      	 return (new Integer(0));
       } // end of if ()
       
       // recursive step for left and right subtrees
      Integer lHeight = (Integer)(bt.getLeft().acceptVisitor(this, null));
      Integer rHeight = (Integer)(bt.getRight().acceptVisitor(this,null));
      
      // debug statement to print out intermediate results
      //System.out.println(" " + lHeight + " " + rHeight);

      return new Integer(1 + Math.max( lHeight.intValue(), rHeight.intValue()));
   }
}// HeightVisitor
