CS2 Summer 2006 Assignment 32

Informal Title: Linear List Processing Application

Date of Issue:


Refine the "unrefined code" in a manner consistent with the given constraints. Note that this code makes use of previously defined linear list processing classes.

Demo

init:
deps-jar:
compile-single:
run-single:
( aardvark ant bat cat dove elephant lion mouse rat tiger )
( January February March April May June July August September October November December )
( tiger rat mouse lion elephant dove cat bat ant aardvark )
( December November October September August July June May April March February January )
( 8.0 3.0 3.0 3.0 4.0 8.0 4.0 5.0 3.0 5.0 )
( 7.0 8.0 5.0 5.0 3.0 4.0 4.0 6.0 9.0 7.0 8.0 8.0 )
( 56.0 11.0 9.0 18.0 92.0 88.0 63.0 43.0 47.0 99.0 48.0 42.0 48.0 89.0 78.0 79.0 64.0 71.0 47.0 14.0 )
( 9.0 11.0 14.0 18.0 42.0 43.0 47.0 47.0 48.0 48.0 56.0 63.0 64.0 71.0 78.0 79.0 88.0 89.0 92.0 99.0 )
BUILD SUCCESSFUL (total time: 1 second)

Unrefined Code

package programs;

import datatypes.list.string.sequential.*;
import datatypes.list.numeric.linked.*;

public class LinearListApp {
    
    public LinearListApp() {
    }
    
    public static void main(String[] args) {
        StringLinearList animals = createAnimalList();
        display(animals);
        StringLinearList months = createMonthList();
        display(months);
        StringLinearList rv_animals = reverse(animals);
        display(rv_animals);
        StringLinearList rv_months = reverse(months);
        display(rv_months);
        NumericLinearList lengths_animals = lengths(animals);
        display(lengths_animals);
        NumericLinearList lengths_months = lengths(months);
        display(lengths_months);
        NumericLinearList number_list = createRandomNumberList(20);
        display(number_list);
        NumericLinearList ordered_number_list = sort(number_list);
        display(ordered_number_list);
    }

Constraints

  1. You may only introduce variables if they are local to a method that you are defining. You may not introduce any other variables.
  2. You cannot alter the main method.
  3. The createAnimalList() method is to return a list containing ten animal names in alphabetical order. This list must be created using the addE method.
  4. The createMonthList() method is to return a list containing the twelve month names in chronological order starting with January. This list must be created using the addB method.
  5. The reverse() method is to reverse the given list, without making use of a stack.
  6. The lengths() method is return a list containing the lengths (as real numbers) of the character strings in the given list.
  7. The createRandomList() method is to return a list containing random reals between 0 and 99, with no values to the right of the decimal point.
  8. The sort() method is to return the given list ordered from low to high, making use of a local array to do the work.