Sunday, Nov 18th

Last update12:59:40 PM GMT

Write C code to determine if two trees are identical.

Write e-mail
By identical, we mean that two trees have exact same elements at exact same places. So, that means the root element are same and left sub-trees and right sub-trees are same. 
 
By now, I guess you have got the idea about the solution. Again, RECURSIVE !

	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); 

	}

	

Share this post



Web Hosting