class Matrix {
public static void main
(String[] args
){ int[][] _matrix = new int[6][6];
_matrix[0] = new int[]{0,0,0,0,1,0};
_matrix[1] = new int[]{0,0,0,0,1,0};
_matrix[2] = new int[]{0,0,0,1,1,0};
_matrix[3] = new int[]{0,0,0,1,0,0};
_matrix[4] = new int[]{0,0,0,1,1,0};
_matrix[5] = new int[]{0,0,0,0,1,0};
_matrix[0] = new int[]{1,0,0,0,0,0};
_matrix[1] = new int[]{1,1,1,1,0,0};
_matrix[2] = new int[]{0,0,0,1,0,0};
_matrix[3] = new int[]{0,0,0,0,0,0};
_matrix[4] = new int[]{0,0,0,1,1,0};
_matrix[5] = new int[]{0,0,0,0,1,0};
int _m = 0;
for(int _n = 0; _n < _matrix[_m].length; _n++){
int _value = _matrix[_m][_n];
if(_value == 1){
System.
out.
println("start m = " + _m
+ " n = " + _n
); neighbour(_matrix, _m, _n, -1, -1);
break;
}
}
}
public static void neighbour(int[][] matrix, int m, int n, int mm, int nn){
int _n = n - 1;
if(_n >= 0 && _n != nn){//para não estourar o indice
if(1== matrix[m][_n]){
//para traz
System.
out.
println(" m = " + m
+ " n = " + _n
); neighbour(matrix, m, _n, -1, n);
}
}
int _m = m + 1;
if(_m < matrix.length && _m != mm){//para não estourar o indice
if(1== matrix[_m][n]){
//para baixo
System.
out.
println(" m = " + _m
+ " n = " + n
); neighbour(matrix, _m, n, m, -1);
}
}
/*
*
*/
_n = n + 1;
if(_n < matrix[m].length && _n != nn){//para não estourar o indice
if(1== matrix[m][_n]){
//para frente
System.
out.
println(" m = " + m
+ " n = " + _n
); neighbour(matrix, m, _n, -1, n);
}
}
//nao explora para cima, pois queremos "descer" na matriz
}
}
Y2xhc3MgTWF0cml4IHsKCglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKXsKCQlpbnRbXVtdIF9tYXRyaXggPSBuZXcgaW50WzZdWzZdOwoJCV9tYXRyaXhbMF0gPSBuZXcgaW50W117MCwwLDAsMCwxLDB9OwoJ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