我正在写一个数独求解器,并且我有工作求解功能。
bool Sudoku::solve(int row, int col){
while (board[row][col] != 0){
col++;
if (col > 8){
col = 0;
row ++;
}
if (row > 8){
return true;
}
}
for (int number = 1; number <= 9; number++){
board[row][col] = number;
if (check_row(row,number) && check_col(col,number) && check_box(row,col,number)){
int next_row = row;
int next_col = col;
next_col++;
if (next_col > 8){
next_col = 0;
next_row++;
}
if (next_row > 8)
return true;
// return solve(next_row, next_col);
if (solve(next_row, next_col))
return true;
}
}
board[row][col] = 0;
return false;
}
而且我真的不明白两者之间有什么区别
if (solve(next_row, next_col))
return true;
和
return solve(next_row, next_col);
但是第二行我的功能不起作用