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;
    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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to