Java Reference
In-Depth Information
/** This class supports clone */
public SortMetrics clone() {
try {
// default mechanism works
return (SortMetrics) super.clone();
} catch (CloneNotSupportedException e) {
// can't happen: this and Object both clone
throw new InternalError(e.toString());
}
}
}
The following class extends SortDouble . The SimpleSortDouble class imple-
ments doSort with a very slow but simple sort algorithm (a "selection
sort") whose primary advantage is that it is easy to code and easy to
understand:
class SimpleSortDouble extends SortDouble {
protected void doSort() {
for (int i = 0; i < getDataLength(); i++) {
for (int j = i + 1; j < getDataLength(); j++) {
if (compare(i, j) > 0)
swap(i, j);
}
}
}
}
Now we can write a test harness for sort algorithms that must be
changed only slightly to test a new sort algorithm. Here it is shown as a
driver for testing the class SimpleSortDouble :
 
Search WWH ::




Custom Search