方法一
L *link(L *head)
{
L *p, *q;
p = head->next;
head - >next = NULL;
while ( q ! = NULL)
{
q = p->next;
p = head->next;
head->next = p;
p = q;
}
return head;
}
將原先的鏈表節(jié)點(diǎn)摘取下來(lái)肾扰,使用頭結(jié)點(diǎn)插入的方法再插入,最后實(shí)現(xiàn)單鏈表的逆序
方法二
L *link(L *head)
{
L *pre , *p = head->next, *r = p->next;
p->next = NULL;
while (r != NULL)
{
pre = p;
p=r;
r = r->next;
p->next = pre;
}
head->next = p
return head;
}