Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursion and stack overflow

Status
Not open for further replies.

Leroy1981

Programmer
Jul 22, 2002
46
US
I have a function that calls itself several times before finishing. This function needs to call itself thousands of
times but i the stack isn't big enough so i get a stack overflow error. I know it's possible to increase the stack size but i want to find another solution. the purpose of the function is to fill in part of a picture like the paint can tool in mspaint so if anyone knows another way to accomplish this it would be really helpful.
 
Instead of recursion often are used multiple (not nested) applied loops on the same saved data

Ion Filipski
1c.bmp
 
If you are using fill-algorithm, consider something more efficient.
My advice : A* without heuristics. The fastest possible and no recursion!
 
if the problem are the stacks you sholud try using a type shorter, try using the minimum size required.

I suggest to use the stack library
and dlecra the stacks something like this
#include <stack.h>
typedef stack <int> S

S your_stack_name;
your_stack_name.push(any_integer_identifier);
your_stack_name.pop();

etc



--- LastCyborg ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top