package brstruct.visitors;

import brstruct.BRStruct;
import brstruct.BRStruct.IAlgo;

/**
 * TODO: Define a visitor for a BRStruct<String> which returns, as an Integer,
 * how many Strings are contained in the BRStruct.
 *
 * @author <a href="mailto:alphonce@cse.buffalo.edu">Carl G. Alphonce</a>
 *
 * Created on: Apr 23, 2007
 *
 */
public class QuizVisitor1 implements IAlgo<Object, String, Integer> {

	public Integer emptyCase(BRStruct<String> host, Object _) {
		// there are no Strings in an empty tree
		return 0;
	}

	public Integer nonEmptyCase(BRStruct<String> host, Object _) {
		// answer is 1 (for the String in the datum of host)
		//   plus the number of Strings in the left subtree (calculated recursively)
		//   plus the number of Strings in the right subtree (calculated recursively)
		return 1 + host.getLeft().execute(this,_) + host.getRight().execute(this,_);
	}

}
