Kim created the following interface for Heap. Any comments?
```
public interface Heap
public void add( Comparable
public void setComparator( Comparator
public E top();
public E peek();
public void clear();
public int size();
public boolean isEmpty();
}
```
A couple of comments.
1. Passing in the Comparator in the constructor would be an easier way to ensure that it exists, as opposed to requiring it to be passed in with a separate method. Doing it with a separate method requires that the preconditions of the add method must now specify that Comparator is not null, instead of just the constructor checking that.
2. There is also the possibility that the Comparator and the Comparable element don’t have the same interpretations for <, >, and ==.
3. It isn’t clear what the point is of requiring the parameter to add to be Comparable if you are going to change the ordering through a Comparator.
You might also like to view...
In the bubble sort algorithm, the inner loop iterates __________ for each of the unsorted array elements.
Fill in the blank(s) with the appropriate word(s).
The OLE Object data type is used to identify files that are created in another program and then linked or embedded in the database. _________________________
Answer the following statement true (T) or false (F)