/*头指针,可以发现head是赋值为NULL,而不是head->next*/
//-----------------头插法-------------------
node *head, *p;
head = NULL;
while (……)
{p = (node *)malloc(……);p->data = ……;p->next = head;//此时第一个p的next指针是NULL,其后是head(即前一个p)head = p;//head移动指向p,即head是会改变的
}
//----------------尾插法---------------------
node *head, *p, *q;
head = NULL;
while (……)
{p = (node *)malloc(……);p->data = ……;p->next = NULL;if (head == NULL)head = p;elseq->next = p;q = p;
}