struct list
{
struct list *next;
int value;
};
//head--->p--->q---->r,将q的next指向p;p,q往前移动到q,r
struct list* my_reverse(struct list *pList)
{
struct list *p,*q,*r;
if(pList == NULL) return NULL;
p = pList;
q = p->next;
while(q)
{
r = q->next;
q->next = p;
p = q;
q = r;
}
pList->next = NULL;
pList = p;
return pList;
}
递归方式
struct list* listReverse(struct list *head)
{
if(!head || !head->next) return head;
struct list *res = listReverse(head->next);
head->next->next = head;
head->next = NULL;
return res;
}