Next: Put it all together
Up: Assignment 9
Previous: Fix the performance issue
As an intermediate step toward the grade-sheet sorter, we're
going to make a generic version of Heap and test it using a
simple integer Sorter.
- 1.
- Copy the Comparable class definition from the Priority
Queue assignment. We're going to adapt Heap to work with
Comparable items and create a simple class that is a member of
the Comparable abstract class.
- 2.
- Make a new class named HeapItem with a single integer as an
instance variable. It should implement Comparable (and provide
methods named compareTo and toString). See PQItem for an
example of how to do this.
- 3.
- Compile and run the three class definitions so that they
work again, generating 100 random numbers, inserting them into
the Heap, then removing and printing them.
- 4.
- Move the main method from Heap.java into HeapItem.java.
You will have to change the startup file, and you will have to
qualify some of the method names that didn't use to need it.
Allen B. Downey
1998-11-30