コード例 #1
0
ファイル: misc.cpp プロジェクト: zhihongzeng2002/cppcoding
bool treeMatch(shared_ptr<Misc::tNode> &big, shared_ptr<Misc::tNode> & small) {
    if (!small) return true;
    if (!big) return false;
    if (big->data != small->data)
        return false;
    return treeMatch(big->left, small->left) && treeMatch(big->right, small->right);
}
コード例 #2
0
ファイル: misc.cpp プロジェクト: zhihongzeng2002/cppcoding
bool Misc::isSubTree(shared_ptr<tNode> &big, shared_ptr<tNode> &small) {
    if (!small) return true;
    if (!big) return false;
    bool result=false;
    if (small->data == big->data)
        result=treeMatch(big, small);
    if (!result && big->left)
        result = treeMatch(big->left, small);
    if (!result && big->right)
        result = treeMatch(big->right, small);
    return result;

}
コード例 #3
0
int treeMatch(node_4_h* n1, node_4_h* n2)
{
    if(n2 == NULL)
        return 1;
    if(n1 == NULL)
        return 0;
    
    if(n1->value!=n2->value)
        return 0;
    
    return(treeMatch(n1->left, n2->left) || treeMatch(n1->right, n2->right));
        
}
コード例 #4
0
int traverseTree(node_4_h* n1, node_4_h* n2)
{
    if(n1 == NULL)
        return 0;
    if(n1->value == n2->value && treeMatch(n1, n2))
        return 1;
    return(traverseTree(n1->left, n2) || traverseTree(n1->right, n2));
}