Can you please help me what I am doing wrong!
Can you please help me in understanding how by just adding this line
arr[j][k]=0;//backtrack
makes the code work. It returns null anyways so what is the use of setting the values to 0.
yeah it returns null, but the changes that u have made on array arr that will remain as it is. they are not related right?
yeah but that value will be dropped right as its value is not stored anywhere.
For eg it sees 0 the adds some value to it for eg 1 checks if true the goes on to next 0 now the possibility to solve this sudoku is impossible (assuming) so it returns null that is being caught at a[][]=nulll it checks for all values and it is not possible to construct the so it returns null.
I do not get what is the use of reasignig the value to 0 before returning null as we will be returning null right?
I might be missing some important point but can you please elaborate why do we need to assign it back to 0 before null
see when u assign some value to ur array and then return back to calling function then that update will be reflected in ur calling function as well which we dont want becuase that value leads to unsolvable state.
see whatevr changes u will make in any function call it will get reflected in orginial array so whatever changes u made in function , we need to revert it back to previous(0 ) before going to parent (calling function)
Thanks for clarifying my doubt. Can you please share some resource where I can read about the same as I am unaware of this and wanted to know deep about it so I don’t commit similar mistakes again in future.
…
a)
you should read about how array’s and its values are passed in functions in java i,e are they pass by value or by reference. and how updation will affect the original array.
see java is not my primary language so i cant suggest u any resources .
but i can suggest you one excercise that u can perform and understand the behaviour.
try doing this=>
a) make an array inside main function
b) declare a function and pass the declared array in that function
c) in that function modify any value of the array
d) now print the array in main function and see what u are getting