Equality of two binary search trees constructed from unordered arrays

后端 未结 4 1968
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 02:24

Given two unsorted arrays of size N each, we are to determine if the Binary Search Tree constructed from them will be equal or not.

So, the elements of

4条回答
  •  时光说笑
    2021-02-15 03:16

    Try this:

    int identical(struct node* a, struct node* b) 
    {
        if (a==NULL && b==NULL)
        {
            return(true);
        } 
        else if (a!=NULL && b!=NULL)
        {
            return(a-> data == b-> data && identical(a->left, b->left) && identical(a->right, b->right));
        } 
        else 
            return(false);
    }
    

提交回复
热议问题