实现二叉搜索树 - "incompatible types when returning type 'struct item_t *'..."

implementing a binary search tree - "incompatible types when returning type 'struct item_t *'..."

我正在尝试实现一个二叉搜索树来保存订购库存。库存商品属性存储在这样的节点中:

typedef struct item item_t;
struct item{
    char name;
    int price;
    int quantity;
    item_t *left;
    item_t *right;
};

想法是提示用户输入上述属性,然后将输入的项目添加到节点。这是我到目前为止写的:

item_t *root = NULL;
item_t *current_leaf = NULL;

void prompt_user(){
    /*
    In here contains the code that prompts the user for the item attributes
    and stores it in a variable called input
    */
    insert_node(input);
}

void insert_node(char *input){
    /*If tree doesnt have a root...*/
    if (root == NULL){

        /*Create one...*/
        root = create_node(input);
    }

    else{
        item_t *cursor = root;
        item_t *prev = NULL;
        int is_left = 0;
        int comparison;

        while(cursor != NULL){

            /*comparison will be 1 is the key of input is less than the key   
            of the cursor, and 2 otherwise...*/
            comparison = compare(input, cursor);
            prev = cursor;

            if(comparison == 1){
                is_left = 1;
                cursor = cursor->left;
            }
            else if (comparison == 2){
                is_left = 0;
                cursor = cursor->right;
            }
        }

        if(is_left){
            *prev->left = create_node(input);
            current_leaf = prev->left;
        }
        else{
            *prev->right = create_node(input);
            current_leaf = prev->right;
        }
    }
}

item_t create_node(char *input){

    item_t *new_node = (item_t*)malloc(sizeof(item_t));

    if (new_node == NULL){
        printf("Out of memory. Shutting down.\n");
        exit(EXIT_FAILURE);
    }

    /*Add data to the node...*/
    update_item(input, new_node);

    new_node->left = NULL;
    new_node->right = NULL;

    current_leaf = new_node;

    return new_node;
}

我希望 root 始终指向输入的第一个项目,current_leaf 指向最后处理的项目。 compare returns 1 如果正在处理的项目 (input) 小于最后处理的项目 (current_leaf)。 update_item 是为新节点(叶子)设置数据的东西。

以上内容并不完整,但这是我目前正在做的事情。我正在努力研究如何编写 add_node 以及如何保持 current_leaf 正确更新。

当我尝试编译时出现以下错误:

$ gcc -ansi -pedantic -Wall -o proj2.exe proj2.c
 proj2.c: In function 'insert_node':
 proj2.c:416:14: error: incompatible types when assigning to type'structitem_t *' from type 'item_t'
         root = create_node(input);
               ^
 proj2.c: In function 'create_node':
 proj2.c:470:5: error: incompatible types when returning type 'struct item_t *' but 'item_t' was expected
      return new_node;
      ^
item_t create_node(char *input)

应该是

item_t *create_node(char *input)

您 return 是一个结构,但您应该 returning 类型为 struct item 的指针。