List Processing, Generics, and Iteration (July 6)
Today's tutorial covers list processing in Java using the
GenList class. We will see the use of generics, and will
write methods in both the recursive and iterative style.
The topics for today's tutorial come from lecture modules 9 and 10
You won't be able to do much for this tutorial without the
skeleton code. It's available in a
or a gzipped tar.
- Recursive List Processing
- Reading Java code and comments
Look at the code for the
FrequencyPair class and the
FrequencyListTest class first. You should be able to understand
FrequencyPair class is used and what its function is,
and you should have a rough idea of what the
FrequencyList class does.
Note that we are looking at the tests before we even see the skeleton
code for the class! There is actually a theory which says this is correct -
to write tests for a class before we write the code. This is called
- Implementing the methods
Now look at the skeleton code for the
class. The documentation in this class should be sufficient to completely
describe the behavior of each method. Use recursion to
implement all the methods in the
class except for
Note that you will have to write helper methods for most of these.
FrequencyListTest class to test your implementation.
- Iterative List Processing
Now rewrite all the methods you just implemented using iteration instead
of recursion for the list processing. You shouldn't need any helper methods
now. Again, test with
- One more method...
Now go back and implement the method we skipped,
mostFrequent(int k) First write the method using recursion,
then using iteration. Make use of the provided helper method,
insert. For a final challenge, rewrite
to use iteration instead of recursion.