Write a generic method to find the maximal element in the range [begin, end) of a list. code example
Example: 20. Write a generic method to find the maximal element in the range [begin, end) of a list. 4
public static <T extends Comparable> T maximalElement (List<T> list, int from, int to) {
T max = list.get(from);
for (int i = from + 1; i < to; i++) {
T elem1 = list.get(i);
if (elem1.compareTo(max) > 0) {
max = elem1;
}
}
return max;
}