I am trying to move the false element in 2d array to a different blank space in element
'X*''O'' ''X''O*'
'O''O'' '' ''X'
'O'' ''X''X''O*'
'X'' '' ''X''X'
'X''X''O*''X''O*'
the elements marked with * are false elements. I want to move those false cells to look like this. In other word move all the false elements to blank space in the array
' ''O''X''X'' '
'O''O''O'' ''X'
'O''O''X''X'' '
'X''O''O''X''X'
'X''X'' ''X'' '
This is what I have so far but not getting the result, it only moves one element not all the false elements. And when I try to put break in outer loop it does not work. Any tips please, this is my code so far:
char temp = ' ';
char[][] arr = new char[tissue.length][tissue[0].length];
for (int i = 0; i < tissue.length; i++)
for (int j = 0; j < tissue[i].length; j++){
if (isSatisfied(tissue, i, j, threshold)
arr[i][j] = tissue[i][j];
if ( !isSatisfied(tissue, i, j, threshold)) {
temp = tissue[i][j];
breakloop:
for (int k = 0; k < tissue.length; k++)
for (int l = 0; l < tissue[k].length; l++)
if (tissue[k][l] == ' ') {
tissue[i][j] = arr[k][l];
arr[k][l] = temp;
break breakloop;
}
}
}