分配时不兼容的类型,从BSTNode *到BSTNode *
发布时间:2020-12-16 10:03:26 所属栏目:百科 来源:网络整理
导读:我正在尝试创建一个二叉搜索树.我正在处理插入功能,但我收到了几个不兼容的类型警告. warning C4133: '=' : incompatible types - from 'BSTNode *' to 'BSTNode *' 我在代码的第22,25,36和36行收到了这些警告.我也收到警告警告C4133:’function’:不兼容
我正在尝试创建一个二叉搜索树.我正在处理插入功能,但我收到了几个不兼容的类型警告.
warning C4133: '=' : incompatible types - from 'BSTNode *' to 'BSTNode *' 我在代码的第22,25,36和36行收到了这些警告.我也收到警告警告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 } } 这是我的BstNode头文件 #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 BSTNode;在结构定义和使用之前 BSTNode* parent; BSTNode* left; BSTNode* right; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |