Problem: A Generic max
You have sorted a whole DynamicArray with selectionSort. Often you do not want the whole array in order, though. You just want the single largest element, like the highest card in a hand or the top score on a board. Let’s write max.
Like swap, indexOfMin, and selectionSort, max goes in MoreArrayUtils as a static method, and reaches the array only through its public size and get. When we built DynamicArray we saw why a general-purpose algorithm belongs in ArrayUtils rather than on DynamicArray itself.
You will write max in two forms. They are the same two forms we used for selectionSort. The first form is by natural order, for elements that define their own ordering with Comparable. The second form takes a Comparator, for when the order comes from outside the element.
A working solution is provided in the accompanying code for this practice problem, in the practice package (MoreArrayUtils.java). Run scripts/run.sh to run it.