What you should do is use a non-recursive implementation of the tree
navigation similar to the following code:
DirListS * Stack[50];
Int16 AtStack;
DirListS * AtDirList;
AtStack=-1;
AtDirList = Head;
While (AtDirList->child != NULL && AtDirList->next !=Null && AtStack > -1)
{
// process AtDirList
if (AtDirList->child != NULL)
{
AtStack++;
Stack[AtStack]=AtDirList;
AtDirList=AtDirList->child;
}
else
{
if (AtDirList->next == NULL)
{
if (AtStack > -1)
{
AtDirList = Stack[AtStack]->next;
Stack[AtStack] = NULL;
AtStack--;
}
}
else
{
AtDirList = AtDirList->next;
}
}
}
I don't garentee that the above code is 100% I wrote it off the top of my
head but it should give you the idea.
Richard
----- Original Message -----
From: "Max Bian" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Friday, November 16, 2001 8:06 AM
Subject: Recursive function and stack
> Hi.
>
> I am trying to do the evil things again--I need to build a list structure
and
> then my function need to search through it for certain node.
>
> The node structure is like this:
>
> typedef struct DirListS{
> UInt16 index;
> struct DirListS *child;
> struct DirListS *next;
> Boolean isDir;
> Boolean selected;
> } DirListType;
>
> It is like a familiy tree: all sisters/brothers linked with the "next"
pointer
> and all kids connected to "child". I am using it for a directory
structure.
>
> My problem is: I don't know how to deal with this effectively without
going
> with recursive function calls. I know it is evil for palm because of the
small
> stack size (4kB for 3.x).
>
> My question is, how to figure out how much stack is needed for each
recursion
> in PalmOS? Is that just the sum of all parameters passed, all value
returned
> and all local variables? I need to estimate if in any practical situation
of
> my app, there is no problem of blowing the stack. Which comp. sci. course
> talks about this, btw?
>
> Thanks.
>
> Max
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Find the one for you at Yahoo! Personals
> http://personals.yahoo.com
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/