>
> "Allen" <allenterring!@#att.net> wrote in message
> news:NnUtb.271894$(EMail Removed)...
> > > What are some different approaches to dealing with stack overflows
> in
> > > C++? I'm especially interested in approaches concerned with speed for
> > > infrequent overflows.
> > Even more specifically, I have a recursive BST function for a
> > potentially very large tree. What kinds of schemes have others come up
> with
> > for dealing with stack overruns of this type?
> > 
> >
> > Best wishes,
> > Allen
> >
> >
>
> You can optimize the recursive function to use up less stack, for example
by
> using global (or member) variables instead of local variables.
>
> See if you really need the recursivity. For example, IIRC a search in a
BST
> tree doesn't require a recursive function scheme but can work simply
within
> a loop.
>
> There are other ways to optimize recursive functions.
> But sometimes if there is really no solution then you have to make your
own
> stack and derecursive the whole thing. But think of it as a last ressort,
> and it's a very rare situation.
>
> But I still think that for a BST there is no need for recursivity at all
in
> most, if not all, cases.
>
> Yours,
>
> Tanguy
>
>
Well there are cases where you cannot easily avoid recursivity, like a
prefix run through the tree (or any other depthfirst run), but then if you
have a stack overflow with a well written recursive function it means your
tree is unbalanced and then I suggest you look up for another structure but
similar such as a redblack tree (which is by the way the most common
implementation of std::map, so...)
