next up previous
Next: Make a generic Priority Up: Assignment 3: Priority Queues Previous: Pick up the array

Switch implementations

1.
Rewrite each of the four methods (the constructor, size, insert, and remove) so that they use a Vector instead of an array.

The most complicated thing here is that in order to add something to a Vector, you should typecast it to be an Object (although you don't have to). When you get it back from the Vector, you have to typecast it back to a PQItem.

2.
Test your program using the client code in main.

3.
Format your code nicely, including comments, and print out just the four methods that you modified.

NOTE: One of the nice things about ADTs is that you should be able to change implementations like this without modifying the client code. Thus, you should not have to make any changes in main.

In order to use the Vector class, you have to import the package that contains it. Add import java.util.*; at the beginning of PriorityQueue.java (before the class definition).



Allen B. Downey
1998-09-29