【小白成长撸】--反向链表(一)
void Reserve(point **head)//链表反向链接--招式one { point *p, *q, *r;//定义3个指针变量 p = (point *)malloc(sizeof(point)); q = (point *)malloc(sizeof(point)); r = (point *)malloc(sizeof(point)); q->next = NULL; r->next = NULL; p->next = NULL; p = (*head); q = p->next; r = q->next;//p为首,q,r依次成为后继 (*head)->next = NULL; while (1) { q->next = p; if (r == NULL)//当r成为null时,说明r达到链表尾部,前面全部都反向了 { break; } else { p = q; q = r; r = r->next;//这个招式如果看不出来,可以画一个示意图,画2个循环就看出来了 } } (*head) = q;//头指针放在以前的尾巴上 free(r); }