package brstruct.visitors;

import brstruct.BRStruct;
import brstruct.BRStruct.IAlgo;

/**
 * TODO: Define a visitor for a BRStruct<Integer> which returns, as an Integer,
 * the largest of all the Integers contained in the BRStruct.  (Assume all values >= 0).
 *
 * @author <a href="mailto:alphonce@cse.buffalo.edu">Carl G. Alphonce</a>
 *
 * Created on: Apr 23, 2007
 *
 */
public class QuizVisitor4 implements IAlgo<Object, Integer, Integer> {

	public Integer emptyCase(BRStruct<Integer> host, Object _) {
		return 0;
	}

	public Integer nonEmptyCase(BRStruct<Integer> host, Object _) {
		// largest of a, b and c is max(a,max(b,c))
		return Math.max(host.getDatum(),Math.max(host.getLeft().execute(this,_),host.getRight().execute(this,_)));
	}

}
