链表的反转

1 void reverse(ListNode*& pre,ListNode* cur,ListNode* nxt){
2         while(cur){
3             nxt=cur->next;
4             cur->next=pre;
5             pre=cur;
6             cur=nxt;
7         }
8     }

定义一个这样的函数:   初始: pre指向nullptr ;  最后pre 返回链表的头指针。 

posted @ 2020-03-07 15:26  B_luePhantom  阅读(101)  评论(0编辑  收藏  举报