this code should fail, the recursion backtracking will not work here(ignoring the return type basic error of this code where on void a not null root is returned)
take the case when root is leaf and hence leaf is returned so leaf's sibling (take case where only left leaf is there not the right one) is set using root->sibling->..whereas the root's siblingh as not been set so far and hence this is not a stack problem, it is a queue problem Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Mon, Aug 2, 2010 at 7:09 PM, padmanaban sahadevan <padhu.de...@gmail.com>wrote: > try this code guys.... > > i think there is redundancy in condition checking. > > if so correct me... > > #include<stdio.h> > struct node > { > int data; > struct node* left; > struct node* right; > struct node* sibling; > }; > void connectHorizontal(struct node* root) > { > if(root == NULL) > return root; > else if(root->left==NULL && root->right ==NULL) > return root;//return type is void??????? > else > { > if(root->left !=NULL) > connectHorizontal(root->left); > if(root->right!=NULL) > connectHorizontal(root->right); > if(root->left!=NULL) > { > root->left->sibling = (root->right ? root->right : > (root->sibling->left ? root->sibling->left : (root->sibling->right ? > root->sibling->right : NULL))); > } > if(root->right!=NULL) > { > root->right->sibling = (root->sibling->left ? > root->sibling->left : (root->sibling->right ? root->sibling->right : NULL)); > } > } > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.