Write a C program to create a mirror copy of a tree (left nodes become right and right nodes become left)!
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
This C code will create a new mirror copy tree.
mynode *copy(mynode *root)
{
mynode *temp;
if(root==NULL)return(NULL);
temp = (mynode *) malloc(sizeof(mynode));
temp->value = root->value;
temp->left = copy(root->right);
temp->right = copy(root->left);
return(temp);
}
This code will will only print the mirror of the tree
void tree_mirror(struct node* node)
{
struct node *temp;
if (node==NULL)
{
return;
}
else
{
tree_mirror(node->left);
tree_mirror(node->right);
// Swap the pointers in this node
temp = node->left;
node->left = node->right;
node->right = temp;
}
}
Related Articles
- Write C code to return a pointer to the nth node of an inorder traversal of a BST.
- Write a C program to create a copy of a tree
- Write C code for iterative preorder, inorder and postorder tree traversals
- How do you reverse a singly linked list? How do you reverse a doubly linked list? Write a C program to do the same.
- How do you reverse a singly linked list? How do you reverse a doubly linked list? Write a C program to do the same.


