I have 2D integer array named arry like this:
[6, 2, 7]
[3, 6, 7]
[5, 6, 1]
[5, 3, 4]
[5, 3, 8]
I want to sort it in the way this would be the result (in order to do so I create new array of the same size, named table):
[3, 6, 7]
[5, 6, 1]
[5, 3, 4]
[5, 3, 8]
[6, 2, 7]
And I have this code:
for (int k = 0; k < numOfArrays; k++) {
int smallest = 2147483647;
int indexSmallest = 0;
for (int h = 0; h < numOfArrays; h++) {
if (arry[h][0] < smallest) {
smallest = arry[h][0];
indexSmallest = h;
}
}
tabel[k] = arry[indexSmallest];
arry[indexSmallest][0] = 2147483647;
}
for (int k = 0; k < numOfArrays; k++) {
System.out.println(Arrays.toString(tabel[k]));
}
The result is:
[2147483647, 6, 7]
[2147483647, 6, 1]
[2147483647, 3, 4]
[2147483647, 3, 8]
[2147483647, 2, 7]
I don't understand how can table contain 2147483647, if I've never set any value of table to 2147483647?
arry[indexSmallest][0] = 2147483647;does?