突然想不清楚了啊,那个链表翻转问题,为什么要这么写
就是迭代的那种方式
struct ListNode* reverseList(struct ListNode *l) {
struct ListNode *pre = l, *now = l->next;
struct ListNode *head = l;
while(now) {
pre->next = now->next; // (1) 将 now 从链表中剥离出来;
now->next = head; // (2) 将 now 插入到之前的链表头之前;
head = now; // (3) 让 now 成为新的链表头;
now = pre->next; // (4) now 也前进一格;
}
return head;
}