我试图为我的二进制搜索树提供一个简单的搜索功能,但它给了我关于不兼容指针类型的警告。如果有人能够指出我做错了什么或留下了什么建议,那将非常感激:
bst_node* find_node(bstree* bst, unsigned long phone){
if(bst->root == NULL || phone == bst->root->phone)
return bst->root;
if(phone < bst->root->phone)
return find_node(bst->root->left, phone);
else
return find_node(bst->root->right, phone);
}
以下是typedef和structs:
typedef struct bst_node bst_node;
typedef struct bstree bstree;
struct bst_node
{
bst_node* left;
bst_node* right;
bst_node* parent;
unsigned long phone;
char *name;
};
struct bstree
{
struct bst_node* root;
int count;
};
错误消息:
warning: passing argument 1 of ‘find_node’ from incompatible pointer type [-Wincompatible-pointer-types]
return find_node(bst->root->left, phone);
note: expected ‘bstree * {aka struct bstree *}’ but argument is of type ‘bst_node ** {aka struct bst_node **}’
bst_node* find_node(bstree* bst, unsigned long phone) {
&#39;其他&#39;出现同样的错误功能
答案 0 :(得分:0)
解决上述问题。 致tkhurana96的信用
bst_node* find_node(bstree* bst, unsigned long phone){
if(bst->root == NULL || phone == bst->root->phone)
return bst->root;
if(phone < bst->root->phone)
bstree subtree_left = {bst->root->left, 0};
return find_node(&subtree_left, phone);
else
bstree subtree_right = {bst->root->right, 0};
return find_node(&subtree_right, phone);
}