package listFW.visitor; import listFW.*; /** *

Title:

*

Description: Remove the minimum element from a list of Integer

*

Copyright: Copyright (c) 2002 by DXN - All rights reserved

* @author DXN * @version 1.0 */ public class RemMin implements IListAlgo { private static class AccMin { public Integer _accMin; public IList _accList; public AccMin(Integer m, IList acc) { _accMin = m; _accList = acc; } } private IListFactory _fact; public RemMin(IListFactory f) { _fact = f; } public Object emptyCase(IEmptyList host, Object inp) { return host; } public Object nonEmptyCase(INEList host, Object inp) { AccMin am = (AccMin)host.execute(new IListAlgo() { public Object emptyCase(IEmptyList host, Object min) { return new AccMin((Integer)min, _fact.makeEmptyList()); } public Object nonEmptyCase(INEList host, Object min) { int m = ((Integer)min).intValue(); int f = ((Integer)host.getFirst()).intValue(); if (f < m) { min = host.getFirst(); } AccMin temp = (AccMin)host.getRest().execute(this, min); if (host.getFirst().equals(temp._accMin)) { return temp; } else { return new AccMin(temp._accMin, _fact.makeNEList(host.getFirst(), temp._accList)); } } }, host.getFirst()); return am._accList; } }