Problem with N-Queens

This is my attempt at the N-Queens problem. I ran into a huge problem and can't solve it. This is the class that manipulates the objects in a way that allows them (or is supposed to allow them to) solve the problem.
The constraints are that two stacks must be used. One stack is called -- stack; the other is called -- comp_stack.
The member function .inc_col() increases the column by one. The .inc_row() increases the row by one.
Please inform me if anything else needs explanation.
I believe the problem is that when the stack gets down to (row 1, column 1) it ends up increasing the row until it deletes it.
The strange thing is that the output gets the correct solution for 5 queens and for 4 queens it gets the right solution for all columns except column 1 which is not present.
Please ask for more clarity -- I am a noobie so I'm sure there are problems with my explanation.


void Game::compare(queen queen_curr)
{
///////////base case if more queens than columns Return;
if(queen_curr.get_col() > max)
return;

////////////////////////initialize initial value of Q_curr to check it at the end to see if it has changed
queen queen_initial = queen_curr;




//////////////////////////transfer items from stack to compare values Value are stored from lowest on top to highest on bottom
MoveToStack();


////////////////////////////compare Q to stack values
while(stack->empty() != 1)
{

//if row # is higher than board # of rows add one to value on top of stack and use compare function on that value
if(Queen_curr.get_row() > max)
{
MoveToComp();////move everything to the complementary stack which will store values from highest on top to lowest on bottom
Queen new_queen = stack->pop();/////Check previous value
new_queen.inc_row();///////increase the row of the prev value
compare(new_queen);///////send value through recursion
}
else if(queen_curr == stack->get_top())
{queen_curr.inc_row();}//add one to row of current queens if it is in the path of other queen
else
{comp_stack->push(stack->pop());}////check current queen against the next queen on the stack
}
/////////////////////////////////check to see if value should be chekced again through recursion
//////--that is the original value has changed
if(queen_curr != queen_initial)
compare(queen_curr);
////////////Otherwise check next value on the stack
else
{
comp_stack->push(queen_curr);
Q_coor new_queen = queen_curr;
new_queen.inc_col();
new_queen.set_row(1);
compare(queen_val);
}

}
Topic archived. No new replies allowed.