Sudoku solving algorithm with back-tracking

后端 未结 2 1512
一个人的身影
一个人的身影 2021-02-15 14:14

I\'m looking to implement a very simple algorithm that uses brute-force back-tracking to solve Sudoku grids. The problem I\'m facing is that in my implementation I included two

2条回答
  •  再見小時候
    2021-02-15 14:52

    I was able to store the 'row' and 'col' values of the empty cells that I kept loosing with each recursive call by storing them in a Stack instance variable of the Sudoku class. The findNextZero() method pushed the 'row' and 'col' values into two empty stacks. Then, I restructured the rest of the program to access this information through the peek() method, and in case i had to backtrack I simply popped the last two values and set the number on the grid corresponding to those values to 0.

提交回复
热议问题