
/**
 * sizeVisitor.java
 *
 *
 * Created: Tue Oct 15 22:12:08 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */

public class SizeVisitor implements Visitor{
   // default constructor is automatically available
   
   public Object operation(Object obt, Object inp)
   {  
      BTree bt = (BTree) obt;
      
      // empty case 
      if ( bt == null) {
	 return (new Integer(0));
      } // end of if ()
      
      // base case: leaf
       if ( (bt.getLeft()==null)&& (bt.getRight()==null) ) {
      	 return (new Integer(1));
       } // end of if ()
       
       // recursive step for left and right subtrees
      Integer lSize = (Integer)(bt.getLeft().acceptVisitor(this, null));
      Integer rSize = (Integer)(bt.getRight().acceptVisitor(this,null));
      
      // debug statement to print out intermediate results
      //System.out.println(" " + lSize + " " + rSize);

      return new Integer( lSize.intValue() + rSize.intValue());
   }
}// sizeVisitor
