0

我正在尝试创建一棵二叉树。我正在尝试编写一个将新节点插入树的函数。它有两个参数:父节点和新节点。

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

4

1 回答 1

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 编译它没有错误和警告。

于 2018-01-07T02:34:23.443 回答