java - what is wrong with my backtracking algorithm? (sudoku solver, stackoverflow) -


Below is a method that solves Sudoku with backtracking algorithm .. or what i want to do The private boolean fillgrid (int [] [] a) {If (! (A (search) (A)) this method shows that if the assigned grid return is correct; For (int i = 0; i & lt; a.length; i ++) {for (int j = 0; j & lt; a.length; j ++) {if (a [i] [j] == 0) {// If an [i] [J] has been unassigned, (for example, intuit = 1; nm & lt; = 9; num ++) works below {if (noConflict (a, i , J, num), and noConflictGrid (a, i, j, digits)) a [i] [j] = num; If (fillgrid (a)) // recurse return true; A [i] [j] = 0; // Whenever false was unassigned to try again; } } } } return false; }

But when I run it, I gave StackHowflow to Stackoverflow points to fill the points (A) with a 'recurse' comment, and (! ) Is below the method to find:

  Private boolean search (int [] [] a) {for (int [] b: a) {for (int c: b) {if (c = = 0) return true; } } return false; }   

Anybody please tell me what is wrong with the code?

  if (noConflict (a, i, j, num) & amp; amp ; Amp; amp; amp; amp; not;   

Are you sure this always is correct If it is not, then the state of a does not change the status of fillGrid (a) before the next call and we call the same method with the same input Go back to a class, which leadership for the stack overflow.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -