开发者

Understanding of a C code required

int Size(struct node* node)
{
   if(node == NULL)
   {
      return 0;
   }
   else if(node != NULL)
   {
      return (Size(node->left) + 1 + Size(node->right));
   }
}

Hi, can anybody please post the stack trace for the following piece of code.

Lets say if we insert the values 2, 1, 10, 5... Then what could be the stack representation during the recursion process.. Pleas开发者_JAVA技巧e, its very urgent, and its very confusing too...


Why not simply use printf? One when entering and one when leaving the function:

int Size(struct node* node)
{
    printf("Enter %d\n", ( node ? node->value : -1 ));
    ...
    printf("Leave %d\n", ( node ? node->value : -1 ));
}


Try using gdb and see the backtrace/bt command for gdb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜