top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Check whether a Tree and its Mirror Image are same?

+6 votes
151 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...