我正在尝试创建一个二叉树。我正在尝试编写一个将新节点插入树中的函数。它有两个参数:父节点和新节点。
struct node {
int value;
struct node * left;
struct node * right;
void (*insert)( struct node*, struct node*);
}
void treeInsert( struct node* this, struct node* new){//this is the line that gives the error
if ( new->value < this->value ){//this will insert it into the left one
if (this->left == NULL){
this->left = new;
} else {
this->left->insert( this->left, new);
}
} else {//this will insert it into the right one
if (this->right == NULL){
this->right = new;
} else {
this->right->insert( this->right, new);
}
}
}
当我使用TCC编译时,我收到错误:error: too many basic types
答案 0 :(得分:3)
我不知道TCC,但是gcc在struct
结束时警告说分号丢失了。
b.c:10:1: error: expected ‘;’, identifier or ‘(’ before ‘void’ void treeInsert( struct node* this, struct node* new){...
struct node {
int value;
struct node * left;
struct node * right;
void (*insert)( struct node*, struct node*);
};
使用该分号,gcc编译它没有错误和警告。