链表------单向链表的反转
2016-08-21 23:27
369 查看
三指针法遍历,一次遍历则完成反转:
<span style="font-size:18px;">ListNode* ReverseList(ListNode* pHead) { //no node if(pHead==nullptr) return pHead; ListNode* pre=nullptr,*mid=pHead,*last=nullptr; //more node/single node while(mid->next!=nullptr){ //confirm the location last=mid->next; mid->next=pre; pre=mid;mid=last; } mid->next=pre; pHead=mid; return pHead; }</span>
相关文章推荐
- [算法]反转单向链表和双向链表
- 单向链表的反转
- C递归实现单向链表的反转
- 数据结构之单向链表操作1-(插入,删除,交换,反转,排序等操作)
- 面试 居然问如何 反转单向链表~~
- 单向链表反转(java)
- 单向链表的反转是一个经常被问到的一个面试题,也是一个非常基础的问题。比如一个链表是这样的: 1->2->3->4->5 通过反转后成为5->4->3->2->1。
- OJ--单向链表反转
- 【链表】反转单向链表
- 单向链表反转
- 使用递归和非递归方式反转单向链表
- 反转单向链表的实现
- C语言(8) - 反转单向链表
- 单向链表的反转
- 《算法之美》の链表问题の单向链表的反转
- 单向链表反转算法——递归版和迭代版
- 链表-Reverse Linked List(反转单向链表)
- 使用递归和非递归方式反转单向链表
- 数学解题(一)单向链表反转
- 单向链表遍历反转 Javascript实现