Monday, December 14, 2015

Check if two Binary Tree are same

    public boolean isTreesSame(BinaryTree T1, BinaryTree T2)    {
        if(T1==null && T2==null)
            return true;
        if(T1==null || T2==null)
            return false;
        if(T1.data==T2.data
                && isTreesSame(T1.left, T2.left)
                && isTreesSame(T1.right, T2.right))
            return true;
        return false;
    }

No comments:

Post a Comment

UA-39217154-2