2 tree identical.txt

来自「It is an ebook about trees」· 文本 代码 · 共 27 行

TXT
27
字号
Write C code to determine if two trees are identical 

Discuss it!          




struct Bintree{
    int element;
    struct Bintree *left;
    struct Bintree *right;
};

typedef struct Bintree* Tree;

int CheckIdentical( Tree T1, Tree T2 )
{
    if(!T1 && !T2) // If both tree are NULL then return true
        return 1;
    else if((!T1 && T2) || (T1 && !T2)) //If either of one is NULL, return false
        return 0;
    else 
        return ((T1->element == T2->element) && CheckIdentical(T1->left, T2->left) && CheckIdentical(T1->right, T2->right));
        // if element of both tree are same and left and right tree is also same then both trees are same
}
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?