struct BinaryTreeNode{
int data;
BinaryTreeNode *left;
BinaryTreeNode *right;
};
//find a A-node that equals B-root,send it to the core func
//judge:root--left--right,and recursion
bool SubTree(BinaryTreeNode *pRootA,BinaryTreeNode *pRootB){
bool result=false;
if(pRootA==NULL||pRootB==NULL)
return result;
if(pRootA->data==pRootB->data)
result=SubTree_core(pRootA,pRootB);
//which means rootA->data=rootB->data,but not all nodes
if(!result)
result=SubTree(pRootA->left,pRootB);
if(!result)
result=SubTree(pRootA->right,pRootB);
return result;
}
//get 2 trees whose roots are equal
//judge whether A-Node always equal B-node till B-null
bool SubTree_core(BinaryTreeNode *pRootA,BinaryTreeNode *pRootB){
if(pRootB==NULL)
return true;
if(pRootA==NULL)
return false;
if(pRootA->data!=pRootB->data)
return false;
return SubTree_core(pRootA->left,pRootB->left)&&
SubTree_core(pRootA->right,pRootB->right);
}