Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

node *makeMirrorCopy(node *root); Description: A function that creates a new tre

ID: 3730654 • Letter: N

Question

node *makeMirrorCopy(node *root);

Description: A function that creates a new tree, which is a reflection of the tree rooted at root. This function must create an entirely new tree in memory. As your function creates a new tree, it must not destroy or alter the structure or values in the tree that was passed to it as a parameter. Tampering with the tree rooted at root will cause test case failure.

Returns: A pointer to the root of the new tree. (This implies, of course, that all the nodes in the new tree must be dynamically allocated.)

typedef struct node

{

int data;

struct node *left, *right;

} node;

Explanation / Answer

Please find my answer.

node *makeMirrorCopy(node *root)
{
node *temp;

if(root==NULL)
return(NULL);
  
temp = (node *) malloc(sizeof(node));
temp->value = root->value;

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

return(temp);
}