public void question(int col, int n, Node<Integer> part_soln) {
if (col==0) stack.push(part_soln);
else for (int row=1; row<=n; row++)
{ if (!exists(row,part_soln) && !unsafe(col,row,col+1,part_soln))
{ Node<Integer> new_soln = new Node<Integer>(row,part_soln);
question(col-1,n,new_soln);
}
}
}
i was inserting part_soln into the stack, but now i want to get the first part_soln instead of the stack, i will break the loop once i get the part_soln, i modify the question become
public void question(int col, int n, Node<Integer> part_soln) {
if (col==0) return part_soln;
else for (int row=1; row<=n; row++)
{ if (!exists(row,part_soln) && !unsafe(col,row,col+1,part_soln))
{ Node<Integer> new_soln = new Node<Integer>(row,part_soln);
question(col-1,n,new_soln);
}
}
return null;
}
the problem occurs, i cant get the first element in the stack but keep getting "null" as an answer, any suggestion?