I'm stuck on an assignment where I'm supposed to use helper methods to sort rows and columns in a 2D int array in Java. It's explicitly required to use two different methods to sort an array. Anyways so here is my code for sorting a row
public static void sortOneRow(int[] arr1) {
int temp;
for (int i = 0; i < arr1.length; i++) {
for (int j = i + 1; j < arr1.length; j++) {
if (arr1[i] > arr1[j]) {
temp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = temp;
}
}
}
And here's to sort a column if given an input parameter representing the 2D array and the column index:
public static void sortOneColumn(int[][] x, int colNo) {
// Sorting one column
int[] thisCol = new int[x.length];
for (int i = 0; i < x.length; i++) {
thisCol[i] = x[i][colNo];
}
// Sort
sortOneRow(thisCol);
for (int i = 0; i < x.length; i++) {
x[i][colNo] = thisCol[i];
}
Now, how do I call these two methods in another method that only takes in the 2D Array and I have to first sort rows then sort columns?