Skip to content

Instantly share code, notes, and snippets.

@musti2304
Created May 3, 2017 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musti2304/25c5ad7a806f1b37b0ced62ea2560fe5 to your computer and use it in GitHub Desktop.
Save musti2304/25c5ad7a806f1b37b0ced62ea2560fe5 to your computer and use it in GitHub Desktop.
Sort the numbers within the array of a two dimensional array
public static void bubbleSort(Integer[][] array) {
for (int i = 0; i < array.length; i++) {
for (int m = array[i].length; m >= 0; m--) {
for (int j = 0; j < array[i].length - 1; j++) {
int k = j + 1;
if (array[i][j] > array[i][k]) {
swapNumbers(i, j, k, array);
}
}
}
}
System.out.println(Arrays.deepToString(array));
}
private static void swapNumbers(int i, int j, int k, Integer[][] array) {
int temp;
temp = array[i][j];
array[i][j] = array[i][k];
array[i][k] = temp;
}
public static void main(String[] args) {
Integer[][] array = new Integer[][] {
//Paste the two dimensional array you want to be sorted
};
bubbleSort(array);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment