Module hw06

Class SumRevAlgo

java.lang.Object
provided.listFW.visitors.SumRevAlgo
All Implemented Interfaces:
IListAlgo

public class SumRevAlgo extends Object implements IListAlgo
Returns the sum of a list of integers using reverse accumulation. The input parameter is not used ("nu").
  • Constructor Details

    • SumRevAlgo

      public SumRevAlgo()
  • Method Details

    • emptyCase

      public Object emptyCase(MTList host, Object... nu)
      Returns zero always.
      Specified by:
      emptyCase in interface IListAlgo
      Parameters:
      host - the MTList that is executing this algorithm.
      nu - a variable number of input parameters that can be used for any purpose.
      Returns:
      result from calling this method. The type of the result is problem-specific and may be null.
    • nonEmptyCase

      public Object nonEmptyCase(NEList host, Object... nu)
      Returns first plus the sum of the rest of the list.
      Specified by:
      nonEmptyCase in interface IListAlgo
      Parameters:
      host - the NEList that is executing this algorithm
      nu - a variable number of input parameters that can be used for any purpose.
      Returns:
      result from calling this method. The type of the result is problem-specific and may be null.