Computer Science 136 |
Lab 4: Comparators are my favorite Sort of Vectors
Due: Wednesday, October 12, 2005 at 9:00 AM
Short Answers
Complete the following problems from the book and turn them in as a text file lab4.txt at the start of lab.
4.20, 4.22 (describe what you would do rather than writing code), 4.24, 5.4, 5.6, 5.18
Lab Program
Do the laboratory at the end of Chapter 5. Come to lab with a sketch of what you plan to do to implement the sorting procedure in MyVector.
Please note the following clarifications, modifications, and explanations relating to the lab procedure outlined in the text:
public class MyVector<T> extends structure.Vector<T>
Keep in mind that as an extension of structure.Vector, methods of MyVector will have access to instance variables and methods declared as protected in the structure.Vector implementation. Make good use of this fact!
public void sort(Comparator<T> c)
Think about how you will modify the algorithm to use Comparators instead of base types or Comparables. Section 5.8 of the text discusses Comparators, but note that Java 5's Comparators are generic, so you should declare your classes that implement Comparator to take the specific type that it is to be used to compare. For example:
public class CastleComparator
implements java.util.Comparator<Castle> {
...
}
Thus, the compare method you write will take parameters (in this case) of type Castle. This means you will not need the casts you see in the text examples.
You may choose from the data files I have provided in the "labs/comparators" directory in the cs136 area on cortland or in my shared area on FreeBSD. See the README file there for more information. You may also use some other data that you find interesting. If you have ideas about this, check with me before or during lab to make sure it's a reasonable thing to do.
When you're finished, create and submit a tar file lab4.tar that includes the following: