Saturday 28 July 2012

Given two binary trees, write a compare function to check if they are equal or not. Being equal means that they have the same value and same structure.


int compareTree(struct node* firstTree, struct node* SecTree){
 if (firstTree==NULL && secTree==NULL) 
     return(true);
 else if (firstTree!=NULL && secTree!=NULL) {
   return(firstTree->data == secTree->data && compareTree(firstTree->left, secTree->left) && compareTree(firstTree->right, secTree->right));
}
    else  return(false);
} 

No comments:

Post a Comment