top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Check whether a Tree and its Mirror Image are same?

+6 votes
601 views
                    50                      50
                   /  \                    /  \
                  20     30              30   20
Sample Tree<---   /  \                       /  \   ----> Mirror image
               70      80                   80   70
              /  \    \                    /    /  \  
             10  40     60                60   40   10
posted Nov 23, 2013 by Mona Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
 /* compares tree and its mirror image */
    int compare(bt *list, bt * list1)
    {
        int d;
        if (list == NULL && list1 == NULL)
        {
            return 1;
        }
        else if (list != NULL && list1 != NULL)
        {
            return(list->value == list1->value &&
            compare(list->l, list1->l) &&
            compare(list->r, list1->r));
        }
        else
        {
            return 0;
        }
    }
answer Nov 23, 2013 by Vikas Upadhyay
+1 vote
void mirror_image(bt * list)
{
    bt * temp1;

    if (list == NULL)
    {
        return;
    }
    temp1 = list->l;
    list->l = list->r;
    list->r = temp1;
    mirror_image(list->l);
    mirror_image(list->r);
}
answer Nov 23, 2013 by Anuj Yadav
...