Я получаю сообщение об ошибке «Конфликтующие типы для« удалить »в строке, где я определяю функцию удаления. Большинство случаев этой ошибки возникает при вызове функции перед ее объявлением. Тем не менее, я звоню на мой remove() в основной функции, предварительно определив его. Тогда, почему ошибка?!?Ошибка: конфликтующие типы для 'remove'
#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");
}
Вы, сэр, гений! Идет тонна. – iamrkcheers
@iamrkcheers Рад, что я мог помочь. Не стесняйтесь [принять этот ответ] (http://stackoverflow.com/help/accepted-answer), если вы сочтете это полезным. – dbush