I need to write up a generic method that takes as an input a generic 2D array and sorts it. The method should use comparable or comparator.
The code I've written so far looks like this:
public static <T extends Comparable<T>> void sort(T[][]stuff) {
T swap = stuff[0][0];
T temp;
for (T[] row : stuff) {
for (T elt : row) {
if (elt.compareTo(swap) > 0) {
temp= swap;
swap = elt;
elt = temp;
}
}
}
}
I took the idea from another StackOverflow post that showed how to get the biggest number from a 2D array and all this code does is this.