package lrs.visitor; import lrs.*; /** * Helper to reverse a list. * @since 10/05/01 * @author DXN */ class ReverseHelp implements IAlgo { public static final ReverseHelp Singleton = new ReverseHelp(); private ReverseHelp() { } /** * Does nothing because the host is empty. * From top to host is the reverse of the original list. * @param host the remaining tail of the list to be reversed. * @param top from top to host is the reversed list so far. * @return null. */ public Object forEmpty(LRStruct host, Object top) { return null; } /** * Removes the host's first and insert it to the front of the top, and * recurs. * @param host the remaining tail of the list to be reversed. * @param top from top to host is the reversed list so far. * @return null. */ public Object forNonEmpty(LRStruct host, Object top) { Object hostFirst = host.removeFront(); // host has "advanced". ((LRStruct)top).insertFront(hostFirst); return host.execute(this, top); } }