【发布时间】:2015-05-04 20:53:47
【问题描述】:
我有这个代码
struct Node {
int data;
struct *Node next;
};
struct Node *head;
void insert(int x) {
node* temp = (node*)malloc(sizeof(struct node));
temp->data = x;
temp->next = head;
head = temp;
}
int main()
{
head = NULL;
}
我正在关注这个video,看起来代码有效。不过我很难把它放在一起。
我们有一个节点头,它在 main 方法中最初设置为 NULL。
linkedlist 包含一个 int 和 next。此插入代码将数据设置为 int 并位于 head 旁边。然后它设置头部温度。
由于我们将 temp.next 设置为 head 然后 head = temp ,这难道不会让 head 得到 int ,然后让它一遍又一遍地指向自己吗?
到目前为止,我只对 linkedlist 进行了迭代,其中最后一个 next 为 NULL。
【问题讨论】:
标签: c