Hi guys , I'm giving you the full C# project I have uploaded , since I'm working with windows form , so you can see the source code and run it .
And now , to explain my problem .
The program I wanted to make is sudoku solver . Now , It's something I'm only making for fun , so if you think it's going to take you too much time to help me , do not give yourself a hard time , it's enough that you even read this post .
Now , in this code , there are 2 main functions
void upisi( int i, int j, int p)
this function is the first one that gets called , it takes parameters i and j for
rows and columns , and p is the number that is being checked .
The logic I used for solving was my own , so please don't make me feel embarassed :-D , I'm sure there are many better ways for solving this , but I wanted to try it on my own ..
So basically , the sudoku fields are 2-dimensional textBox array ,so it acts like a matrix
and I'm starting from field at 0,0 .
First , I'm checking if I'm out of bounds (second coordinate bigger than 8 ) , if so , go into next row (++i) .
If I'm not out of bound , then check if the field is enabled (enabled fields are those that need to be filled) , if not go to the next field .
If I'm not out of bounds , and the field is enabled , then check to see if the number I'm testing is less then 10 (1-9 ), if that condition is satisfied , then again check if the textbox CAN be filled with that number (if rows , columns and it's square do not contain the same number ).
If all those conditions are fullfiled , the text box is filled with that number , and the program moves on to the next field , however , if the number is not less than 10, that means that the field can not contain anything from 1 to 9 , so I need to go back at the previous field and try another combination
thats where I call the function
void vrati(int i, int j)
It simply checks what the number on the field is and tries another possible , if this number also exceeds the bounds ( not < 10), than it will simply call itself again until it can fulfill the condition .
If the number is good to go , it calls the function void upisi( int i, int j, int p) and this function fills that textbox with the number and moves on .
Now , I'm sorry for this long intro , but I wanted to clear this code up, because I know I'm pretty messy when it comes to code writing .
This code seems to be working quite well , BUT when I try it on some easy sudokus , it gives me the stack overflow error and crashes .
The code is working perfectly fine even if I do not enter a single number , but when I try to solve some puzzled , it crashes .
If anyone could help me with this I would appreciate this so much , it's not important for me to have the sudoku solver , but to understand where my mistake was .
Thanks in advance !