Mirror of a binary tree
Well, one thing that always fascinates me when it comes to numbers or words is a palindrome. My blog here is a very interesting yet a simple program that would help us in finding the mirror of a binary tree and, when you place the original binary tree next to its mirrored binary tree, they would seem like a palindrome to us. Like the one in the following image.
For those who are quite not strong in binary trees, this post might be of good help to grasp knowledge on some major operations in binary trees.
/* single node of a tree with its data, left child, right child */
struct node* left; //left child of a node
struct node* right; //right child of a node
/* new node allocation */
struct node* newnode(int data)
struct node* n_node=(struct node*)malloc(sizeof(struct node));
/*Inorder traversal of a binary tree */
void Inorder(struct node* root)
/* mirroring the tree with a temporary node that is used for swapping*/
void mirror(struct node* root)
struct node* temp=(struct node*)malloc(sizeof(struct node));
struct node* root;
printf("\n Mirroring the binary tree......\n");
Have any queries, please do leave a comment.
4 2 1 5 7 3 6
Mirroring the binary tree……
4 2 1 5 7 3 6|6 3 7 5 1 2 4
Latest posts by abirami vijayakumar (see all)