【发布时间】:2020-05-01 05:13:35
【问题描述】:
我正在尝试创建一个将节点添加到链接列表开头的函数。我已经创建了新节点并成功地将新节点指向了链表中的原始标题。但是我不确定如何将我的新节点设置为链表的标题。
void insert_node(BURGER* header)
{
BURGER* tp1;
printf("Enter the details of record to be inserted in the format as\n");
printf("<name>\n<popularity>\n");
scanf_s("%s", &name, sizeof(name));
scanf("%d", &popular);
tp1 = make_node(name, popular);
tp1->next = header;
header = tp1;
//printf("%d", tp1->next->popularity);
printf("\n\n New record inserted at the start of the List\n");
}
亲切的问候
【问题讨论】:
-
这能回答你的问题吗? Adding to the front of a Linked List in C
-
如果这没有帮助建议进行搜索。 Stack Overflow 和整个互联网上有无数的帖子解释了不同的方法。
-
OT:这里的正确术语是“head”,而不是“header”。
标签: c