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

Nat*_*nda 3 c struct

我正在尝试创建一个二叉搜索树.我正在处理插入功能,但我收到了几个不兼容的类型警告.

warning C4133: '=' : incompatible types - from 'BSTNode *' to 'BSTNode *'
Run Code Online (Sandbox Code Playgroud)

我在代码的第22,25,36和36行收到了这些警告.我也收到了warning C4133: 'function' : incompatible types - from 'BSTNode *' to '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
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的BstNode头文件

#ifndef BSTNODE_H
#define BSTNODE_H

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

#endif
Run Code Online (Sandbox Code Playgroud)

Sou*_*osh 5

在您的头文件中

struct BSTNode* parent;
struct BSTNode* left;
struct BSTNode* right;
Run Code Online (Sandbox Code Playgroud)

应该

struct BSTNODE* parent;
struct BSTNODE* left;
struct BSTNODE* right;
Run Code Online (Sandbox Code Playgroud)

因为,在定义成员时,BSTNode不得而知.

否则,你也可以拥有typedef struct BSTNODE BSTNode;之前的结构定义和使用方式

BSTNode* parent;
BSTNode* left;
BSTNode* right;
Run Code Online (Sandbox Code Playgroud)