Stack overflow - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Stack overflow

autoriusautorius Posts: 2Member
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.
[code]
procedure SOLVE (var A : LBOARD; INDEX : integer; var SOLUTION : boolean);
var i : integer;
begin
if SOLUTION = false
then if FULL(A)
then begin
SOLUTION := true;
TextColor(10);
WriteLn('Possible solution found.');
PRINT_CHESSBOARD(A);
end
else if THERE_ARE_POSSIBLE_MOVES(A)
then begin
for i := INDEX downto 1 do
if CAN_BE_MOVED(A, i) and (A[i] = 1)
then begin
MOVE(A, i);
RESET(A, i);
if QUEEN_TO_LEFT(A, i) = 0
then SOLVE(A, QUEEN_TO_RIGHT(A), SOLUTION)
else SOLVE(A, QUEEN_TO_LEFT(A,i), SOLUTION);
end;
end
else begin
TextColor(4);
WriteLn('No possible solution found.');
end;
end;
[/code]

Comments

Sign In or Register to comment.