Sunday, Nov 18th

Last update12:59:40 PM GMT

Write a C program to create a mirror copy of a tree (left nodes become right and right nodes become left)

Write e-mail

This one is an interesting question and is asked in many grade A software companies like Microsoft, Amazon, Adobe, etc.


Here we create a new tree, which is an exact mirror copy of the given root node tree. We start with the root node, and create a new temp root. And then we assign temp's left node with the original root's right node and vice-versa in recursive manner.

mynode *copy(mynode *root)
 mynode *temp;
 temp = (mynode *) malloc(sizeof(mynode));
 temp->value = root->value;

 temp->left  = copy(root->right);
 temp->right = copy(root->left);


Share this post

Web Hosting