below is a method to solve a sudoku with backtracking algorithm.. or that's what I meant to do
private boolean fillGrid(int[][] a){
if(!find(a)) // this method finds if there's unassigned grid
return true;
for(int i = 0; i<a.length ; i++){
for(int j = 0; j < a.length ; j++){
if(a[i][j] == 0){ // if a[i][j] is unassigned, perform things below
for(int num = 1 ; num <=9; num++){
if(noConflict(a, i, j, num ) && noConflictGrid(a, i, j , num))
a[i][j]= num;
if(fillGrid(a)) // recurse
return true;
a[i][j] = 0; // unassigned to try again whenever false;
}
}
}
}
return false;
}
however when I run it, it gave me stackoverflow. the stackoverflow points to fillGrid(a) the one with 'recurse' comment, and (!find(a)). the method find is below:
private boolean find(int[][] a){
for(int[] b: a){
for(int c: b){
if(c == 0)
return true;
}
}
return false;
}
anyone please tell me what's wrong with the code?