[Binary Tree Algorithm] determines whether similar or equivalent to two trees (recursively)

// determines whether two trees are not the same value as a similar tree. 8 
BOOL IsSimilar (BTNode * T1, BTNode * T2) {
     IF (T1 == null && T2 == null ) return  to true ;
     IF (T1 == null || == T2 null ) return  to false ;
     the else {
         return IsSimilar (T1-> lchild, T2-> lchild) && 
            IsSimilar (T1 -> rchild, T2-> rchild);
    }
}
// determine whether the two trees are equal. 9 
BOOL IsEqual (BTNode * T1, BTNode * T2) {
     IF (T1 == null && T2 == null ) return  to true ;
     IF (T1 == null || T2 == null ) return  to false ;
     IF (T1-> T2- Data ==> Data) {
         return IsEqual (T1-> lchild, T2-> lchild) && 
            IsEqual (T1 -> rchild, T2-> rchild)
    }else {
        return false;
    }
}

Guess you like

Origin www.cnblogs.com/zzuuoo666/p/12083178.html