Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4098
Number of posts: 14002

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Stack overflow Posted by autorius on 6 Apr 2013 at 5:25 AM
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;
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;




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.