subTree

struct Tree()
{
int val;
Tree *left, *right;
Tree(int a): val(a), left(NULL), right(NULL){}
}
bool hasSubTree(Tree *root1, Tree * root2){ if(root2 == NULL) return true;
if(root1 == NULL) return false; bool result = false; if(root1->val == root2->val)
result = isSubTree(root1, root2); if(!result)
result = hasSubTree(root1->left, root2);
if(!result)
result = hasSubTree(root1->right, root2); return result;
} bool isSubTree(Tree *root1, Tree * root2){
if(root2 == NULL) return true;
if(root1 == NULL) return false;
if(root1->val != root1->val) return false;
return isSubTree(root1->left, root2->left)
&& isSubTree(root1->right, root2->right);
}

  

上一篇:【AspNetCore】【WebApi】扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat)


下一篇:12.jQuery简单补充