C 分配时类型不兼容,从BSTNode*到BSTNode*

C 分配时类型不兼容,从BSTNode*到BSTNode*,c,struct,C,Struct,我正在尝试创建一个二进制搜索树。我正在处理insert函数,但是我收到了几个不兼容类型的警告 warning C4133: '=' : incompatible types - from 'BSTNode *' to 'BSTNode *' 我在代码的第22、25、36和36行收到这些警告。在我的两个递归调用中,我还收到了警告warning C4133:“function”:不兼容类型-从“BSTNode*”到“BSTNode*”。我用注释标记了下面代码中的错误。这些都是相同的类型,因此我无法

我正在尝试创建一个二进制搜索树。我正在处理insert函数,但是我收到了几个不兼容类型的警告

warning C4133: '=' : incompatible types - from 'BSTNode *' to 'BSTNode *'
我在代码的第22、25、36和36行收到这些警告。在我的两个递归调用中,我还收到了警告
warning C4133:“function”:不兼容类型-从“BSTNode*”到“BSTNode*”
。我用注释标记了下面代码中的错误。这些都是相同的类型,因此我无法找出导致这些警告的原因

//BST.c

#include "BST.h"
#include <stdio.h>
#include <stdlib.h>


void insert(BSTNode* top_of_bst,BSTNode* node){


   //no items in bst, add it to the top
   if (top_of_bst == NULL){
      top_of_bst->node_value = node->node_value;
      top_of_bst->left = NULL;
      top_of_bst->right = NULL;
      top_of_bst->parent = NULL;
      return;
   }

  //if the value is smaller check the left child
  if (top_of_bst->node_value >= node->node_value){
      if (top_of_bst->left == NULL){
         node->parent = top_of_bst;  //HERE IS AN ERROR
         node->right = NULL;
         node->left = NULL;
         top_of_bst->left = node;   //HERE IS AN ERROR
         return;
      }
      //if the left child exists, recurse left
      else
         insert(top_of_bst->left, node);  //HERE IS AN ERROR
   }
   //if the value is bigger check the right child
    else{
       if (top_of_bst->right == NULL){
          top_of_bst->right = node; //HERE IS AN ERROR
          node->parent = top_of_bst;   //HERE IS AN ERROR
          node->left = NULL;
          node->right = NULL;
          return;
       }
       //if the child exists, recurse right
       else
          insert(top_of_bst->right, node);   //HERE IS AN ERROR
    }
}
在头文件中

#ifndef BSTNODE_H
#define BSTNODE_H

typedef struct BSTNODE{
   struct BSTNode* parent;
   struct BSTNode* left;
   struct BSTNode* right;
   int node_value;
}BSTNode;

#endif
struct BSTNode* parent;
struct BSTNode* left;
struct BSTNode* right;
应该是

struct BSTNODE* parent;
struct BSTNODE* left;
struct BSTNODE* right;
因为在定义成员时,
BSTNode
是未知的

否则,您还可以使用
typedef结构BSTNODE在结构定义之前,使用like

BSTNode* parent;
BSTNode* left;
BSTNode* right;

结构应该如下所示。在定义完成之前,不能引用typedef别名

typedef struct BSTNODE{
   struct BSTNODE* parent;
   struct BSTNODE* left;
   struct BSTNODE* right;
   int node_value;
}BSTNode;

这是一个快速使用
struct BSTNODE*
而不是
struct BSTNODE*
。typedef'ed名称在结构定义中还不可用,如果是,您也不需要在它前面加
struct
。具体哪一行?您没有显示任何行号。此外,当
top\u of_bst
为空时,您的代码将崩溃访问其成员,因为您没有首先创建新的
BSTNode