C program to create mirror copy of a tree

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

Solution:

#include<stdio.h>
struct binarysearchtree{
int data;
struct binarysearchtree* left;
struct binarysearchtree* right;
};
typedef struct binarysearchtree* tree;

tree mirror_copy(tree T)
{
if(T==NULL)
return T;
else
{
tree temp1=mirror_copy(T->left);
tree temp2=mirror_copy(T->right);
T->left=temp2;
T->right=temp1;
return T;
}
}


Click Here For More Questions

No comments:

Post a Comment