Write a C program to compute the depth of a binary tree?
maxDepth function would take root node as the input and return the depth of the tree. Its the recursive programming solution to find the depth of the tree
int maxDepth(struct node* node)
{
if (node==NULL)
{
return(0);
}
else
{
int leftDepth = maxDepth(node->left);
int rightDepth = maxDepth(node->right);
if (leftDepth > rightDepth) return(leftDepth+1);
else return(rightDepth+1);
}
}
Write a program to create mirror of a binary tree
Binary Tree Job Interview Questions
This resursive C code will create a new binary tree which would be the mirror copy of the previous binary 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
