Module hw06

Class CountAlgo

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

public class CountAlgo extends Object implements IListAlgo
Returns the count of the number of elements in the list
  • Constructor Details

    • CountAlgo

      public CountAlgo()
  • Method Details

    • emptyCase

      public Object emptyCase(MTList host, Object... nu)
      Returns zero always
      Specified by:
      emptyCase in interface IListAlgo
      Parameters:
      nu - Not used
      host - the MTList that is executing this algorithm.
      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 1 plus the count of the rest of the list.
      Specified by:
      nonEmptyCase in interface IListAlgo
      Parameters:
      nu - Not used
      host - the NEList that is executing this algorithm
      Returns:
      result from calling this method. The type of the result is problem-specific and may be null.