反转链表
来源:互联网 发布:什么软件挣钱快好提现 编辑:程序博客网 时间:2024/06/05 04:43
输入一个链表,反转链表后,输出反转链表后头节点
/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: ListNode* ReverseList(ListNode* pHead) { if(pHead==NULL) return NULL; if(pHead->next==NULL) return pHead; if(pHead->next->next==NULL){ pHead->next->next=pHead; pHead->next=NULL; } ListNode* prev=pHead; ListNode* temp=pHead->next; pHead=pHead->next->next; prev->next=NULL; while(pHead!=NULL){ temp->next=prev; prev=temp; temp=pHead; pHead=pHead->next; } temp->next=prev; return temp; }};
0 0
- 链表反转
- 反转链表
- 单向链表反转
- 链表反转:
- 链表的反转
- 链表反转
- 反转单向链表
- 链表反转
- 单向链表反转
- 单向链表反转
- 链表的反转
- 链表反转
- 反转链表
- 链表反转
- 链表反转
- 链表反转
- 链表反转
- 链表的反转
- [leetcode 28] Implement strStr()
- 《剑指offer》——左旋转字符串
- 单例的创建
- Unity3D 关于Coroutine(协程)使用的研究笔记及关于yield的理解
- 删除数据时的提示效果
- 反转链表
- 47.沙盒机制(简单对象的写入)
- C++基础知识: 公有继承,保护继承,私有继承的总结,私有继承的用意何在
- java解惑--谜题10:八两
- Android开发设置Button的background
- C/C++ Quick Sort Algorithm
- 分区存储
- 合并两个排序的链表
- 使用MATLAB + psychtoolbox 实现的钟表 可以检测反映速度哦