Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
So, i have written recursion which after certain number of calls causes stack overflow. I would like to know if somehow i can avoid this.
procedure SOLVE (var A : LBOARD; INDEX : integer; var SOLUTION : boolean);
var i : integer;
if SOLUTION = false
then if FULL(A)
SOLUTION := true;
WriteLn('Possible solution found.');
else if THERE_ARE_POSSIBLE_MOVES(A)
for i := INDEX downto 1 do
if CAN_BE_MOVED(A, i) and (A[i] = 1)
if QUEEN_TO_LEFT(A, i) = 0
then SOLVE(A, QUEEN_TO_RIGHT(A), SOLUTION)
else SOLVE(A, QUEEN_TO_LEFT(A,i), SOLUTION);
WriteLn('No possible solution found.');
0 · ·