package schemeFactory.visitor; import schemeFactory.*; /** * Reverses the host given the reverse of the list preceding the host. * Passes the accumulated reverse to the constructor.
Note to students: try to write a version where the accumuated reverse is passed as the input parameter. You will learn to appreciate the differences.@author D. X. Nguyen */ class HelpReverse implements IListAlgo { private AList _accReverse; // acumulated reverse so far. public HelpReverse(AList accReverse) { _accReverse = accReverse; } /** * Returns the accumulated reverse because this is the end of the list. * @param host not used * @param input not used * @return IList */ public Object emptyCase(AList host, Object input) { return _accReverse; } /** * Accumulates the reverse by cons-ing the host's first with the accumulated * reverse so far, and recur on the host's rest. * @param host the rest of the list to be reversed. * @param input the accumulated reverse of the list preceding host. * @return IList */ public Object nonEmptyCase(AList host, Object input) { //_accReverse = new NEList(host.getFirst(), _accReverse); return host.getRest().execute (this, null); } }