Created
May 3, 2017 22:17
-
-
Save musti2304/25c5ad7a806f1b37b0ced62ea2560fe5 to your computer and use it in GitHub Desktop.
Sort the numbers within the array of a two dimensional array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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