Write C code to determine if two trees are identical
October 28, 2007 · Filed Under Placement Questions, Tree
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
Here is a C program using recursion
int identical(struct node* a, struct node* b)
{
if (a==NULL && b==NULL){return(true);}
else if (a!=NULL && b!=NULL)
{
return(a->data == b->data &&
identical(a->left, b->left) &&
identical(a->right, b->right));
}
else return(false);
}
Related Articles
- Write C code to determine if two trees are identical
- Write C code to check if a given binary tree is a binary search tree or not?
- Write a C program to create a mirror copy of a tree (left nodes become right and right nodes become left)!
- Write a C program to determine the number of elements (or size) in a tree.
- Write a C program to determine the number of elements (or size) in a tree.


