Next: Put it all together
Up: Assignment 10
Previous: Fix the performance issues
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.
Allen Downey
1999-11-11