我试图将一封信与数据部分进行比较,以便在链表中按字母顺序插入,这有什么问题?
typedef struct{
char data;
struct list_node *next;
}list_node;
typedef struct{
list_node *head;
}list;
我试图执行以下操作:
void input_char(list *my_list, char x)
{
list_node *node = (list_node*)calloc(1, sizeof(list_node));
list_node *tmp = my_list->head;
node->data = x;
if (tmp == NULL)
my_list->head = tmp;
else if (tmp->next == NULL)
{
if (x < tmp->data)
{
node->next = tmp;
my_list->head = node;
}
else
tmp->next = node;
tmp = tmp->next;
}
else
{
if (x < tmp->next->data)
// This following line says "Error, Pointer to incomplete type is not allowed.
{
node->next = tmp->next;
tmp->next = node;
}
tmp = tmp->next;
}
}
答案 0 :(得分:3)
更改
typedef struct{
char data;
struct list_node *next;
}list_node;
到
typedef struct list_node{
char data;
struct list_node *next;
}list_node;
您的编译器不知道struct list_node
是什么,因此您必须声明它。