单链表逆置

来源:互联网 发布:macbook 配件 知乎 编辑:程序博客网 时间:2024/05/18 00:00

单链表的逆置问题,常常遇到,今天总结如下:

方法:头插法:

图示:


代码:

//翻转单链表ListNode* Revers(ListNode* pHead){ListNode* newhead = NULL;ListNode* cur = pHead;while(cur){ListNode* tmp= cur;cur = cur->next;tmp->next = newhead;newhead = tmp;}return newhead;}

0 0
原创粉丝点击