简体   繁体   English

错误:“删除”的冲突类型

[英]Error : Conflicting types for 'remove'

I am getting an error "Conflicting types for 'remove'" at the line where I define my remove function. 我在定义删除功能的行中收到错误“'删除'的冲突类型”。 Most cases for this error occur whilst calling a function before its declaration. 在声明函数之前调用函数时会出现此错误的大多数情况。 However, I'm making calls to my remove() in the main function, whilst having defined it beforehand. 但是,我正在调用main函数中的remove(),同时事先定义了它。 Then, why the error ?!? 那么,为什么错误?!?

    #include<stdio.h>
    #include<stdbool.h>

    struct node
    {
        int data;
        struct node* left;
        struct node* right;
    };

    struct node* newNode(int x)
    {
        struct node* temp=(struct node*)malloc(sizeof(struct node));
        temp->data=x;
        temp->left=NULL;
        temp->right=NULL;
        return temp;
    }

    struct node* insert(struct node* root,int x)
    {
        if (root==NULL)
            root=newNode(x);
        else if (x<=root->data)
            root->left=insert(root->left,x);
        else
            root->right=insert(root->right,x);
        return root;
    }

    struct node* remove(struct node* root,int x)
    {
        if (root==NULL)
            printf("Node not found !\n");
        else if (x==root->data)
        {
            struct node* temp=root;
            root=NULL;
            free(temp);
            printf("Node removed !\n");
        }
        else if (x<=root->data)
            root->left=remove(root->left,x);
        else
            root->right=remove(root->right,x);
        return root;
    }

    bool search(struct node* root,int x)
    {
        if (root==NULL)
            return false;
        else if (x==root->data)
            return true;
        else if (x<=root->data)
            return search(root->left,x);
        else
            return search(root->right,x);
    }

    void main()
    {
        struct node* root=NULL;
        root=insert(root,20);
        root=remove(root,10);
        root=insert(root,8);
        root=remove(root,10);
        root=insert(root,22);
        root=remove(root,22);
        root=insert(root,21);
        root=remove(root,10);
        root=insert(root,12);
        root=remove(root,12);
        root=insert(root,16);
        root=remove(root,10);
        root=insert(root,0);
        root=remove(root,10);
        root=insert(root,11);
        root=remove(root,10);
        root=remove(root,11);
        printf(search(root,10)?"Found\n":"Not Found\n");
        printf(search(root,20)?"Found\n":"Not Found\n");
        printf(search(root,11)?"Found\n":"Not Found\n");
        printf(search(root,17)?"Found\n":"Not Found\n");
    }

When compiling your code, I get this: 在编译代码时,我得到了这个:

/tmp/x1.c:32: error: conflicting types for ‘remove’
/usr/include/stdio.h:154: error: previous declaration of ‘remove’ was here

As you can see, there is a function declared in stdio.h named remove . 如您所见, stdio.h有一个名为remove的函数。 That conflicts with the definition you have. 这与你的定义相冲突。

You'll need to rename your function so it doesn't clash with the definition in stdio.h . 您需要重命名您的函数,以便它不会与stdio.h的定义冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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