Equality of two binary search trees constructed from unordered arrays

后端 未结 4 959
有刺的猬
有刺的猬 2021-02-15 02:42

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:10

    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);
    }
    

提交回复
热议问题