简体   繁体   中英

Dereferencing pointer to incomplete type (struct node)

I am writing a simple AVL tree implementation using C. I am having issues with my code at various parts of. Sometimes I get this error, sometimes dereferencing works quite well.

Here is how my struct node looks:

struct Node
{
    int data;
    struct Node *left;
    struct Node *right;
    int height;
};

Here is where I get the dereferencing error (exactly on if (data < (p->data)) )

struct node* search(struct node* p, int data)
{
    if (!p)
        return NULL;
    if (data < (p->data))
        return search(p -> left, data);
    else if ( data > p -> data )
        return search(p -> right, data);
    else
        return p;
}

Also here:

struct Node remove_min(struct Node *x)
{
 if (x->left == NULL)
     return x->right;
 x->left = deleteMin(x->left);
 return x;
}

Any help would be appreciated. Thanks

struct node更改为struct Node

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM