URI:
   DIR Return Create A Forum - Home
       ---------------------------------------------------------
       techsuns
  HTML https://techsuns.createaforum.com
       ---------------------------------------------------------
       *****************************************************
   DIR Return to: Trees
       *****************************************************
       #Post#: 20--------------------------------------------------
       mirror image 
       By: dinesh Date: August 14, 2012, 10:25 am
       ---------------------------------------------------------
       write an algorithm to obtain the mirror image of a given binary
       tree
       So the tree...
       4
       / \
       2   5
       / \
       1   3
       is changed to...
       4
       / \
       5   2
       / \
       3   1
       #Post#: 35--------------------------------------------------
       Re: mirror image 
       By: satya Date: August 19, 2012, 1:07 am
       ---------------------------------------------------------
       will this one solve the problem??   ??? ???
       void mirror(struct node* node)
       {
       if (node==NULL)
       {
       printf("binary tree is empty\n");
       return;
       }
       else
       {
       struct node* temp;
       mirror(node->left);
       mirror(node->right);
       temp = node->left;
       node->left = node->right;
       node->right = temp;
       }
       }
       #Post#: 36--------------------------------------------------
       Re: mirror image 
       By: dinesh Date: August 21, 2012, 1:35 am
       ---------------------------------------------------------
       yes
       #Post#: 41--------------------------------------------------
       Re: mirror image 
       By: kranthipls Date: August 22, 2012, 9:59 am
       ---------------------------------------------------------
       @Satya I think you need to do a slight change in your program.
       Reason: Since this is a recursive call when we reach the last
       node and when the same function is called with NULL then your
       function prints binary tree is empty but actually it is not. I
       hope you got what I told.
       #Post#: 44--------------------------------------------------
       Re: mirror image 
       By: satya Date: August 22, 2012, 10:38 am
       ---------------------------------------------------------
       yaa,,i had little doubt regarding this.... so i asked.......what
       to do when the node becomes NULL in this case.........just
       return is enough or what?????? o :-\ :-\ :-\
       #Post#: 45--------------------------------------------------
       Re: mirror image 
       By: kranthipls Date: August 22, 2012, 10:43 am
       ---------------------------------------------------------
       I feel yes. Because this is a recursive function you need to
       think of all possible angles
       #Post#: 51--------------------------------------------------
       Re: mirror image 
       By: dinesh Date: August 24, 2012, 1:37 am
       ---------------------------------------------------------
       if (node==NULL)
       {
       return;
       }
       This will suffice
       #Post#: 55--------------------------------------------------
       Re: mirror image 
       By: satya Date: August 24, 2012, 10:32 am
       ---------------------------------------------------------
       ok...thanx. ;D ;D
       *****************************************************