开发者

Understanding of a C code required

开发者 https://www.devze.com 2022-12-29 11:57 出处:网络
int Size(struct node* node) { if(node == NULL) { return 0; } else if(node != NULL) { return (Size(node->left) + 1 + Size(node->right));
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

精彩评论

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

关注公众号