8Qeens problem WITHOUT recursion.
Trying to solve the 8Qeens problem WITHOUT recursion.
Right now I have the following code, for the placing of queens.
//search for places to place the queens
bool add8Queens(int board[8][8], int column)
{
while(column<8)
{
for (int i=0; i<8;i++)
{
if(isValid( board, i, column)) //checks if no other in row, / or, \
{
board[i][column] = 1;
column=column+1;
i=0;
}
else
board[i][column] = 0;
}
return true;
}
}
I can get it to correctly print 5 queens in 5 rows as it should but when it comes to the last 3 their is no safe squares so it does not place them.
How can I backtrack without the recursion? I have tried a few ways but without sucesss.
Step by step
Solved in 2 steps