In ComparatorHeap, write a generic class Heap<E> (on an ArrayList<E>) whose order is given by a Comparator passed to the constructor: the element that the comparator considers the smallest is at the root. Methods: add (sift up), remove (sift down; returns null when empty), peek, size, toString (the array).
With the right comparator the same class is a min-heap, a max-heap or anything else. The first word of the input chooses the order of a heap of words: min (alphabetical), max (reverse alphabetical) or length (shortest first, then alphabetical). Then come the commands add w, remove, peek, show. At the end, empty the heap. For the input
min
add pear
add fig
add banana
show
peek
add apple
remove
show
the program prints
array: [banana, pear, fig]
at the root: banana
removed apple
array: [banana, pear, fig]
Emptying the heap (min): banana fig pear