反转链表
2016-04-09 12:23
323 查看
题目描述
输入一个链表,反转链表后,输出链表的所有元素。思路
很简单的模拟,据说链表相关的题目考的是基本功扎不扎实~/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* ReverseList(ListNode* pHead) { ListNode *last = NULL, *now = pHead, *next = NULL; while (now != NULL) { next = now->next; now->next = last; last = now; now = next; } return last; } };
相关文章推荐
- 如何使用xpdf把本地磁盘上的pdf转化为txt
- Android中CheckBox的使用
- pcl里面的点特征直方图(PFH)
- MP4文件,Web播放器不能边下边播问题
- Ubuntu 14.04 FTP服务器--vsftpd的安装和配置
- 02-Memcached安装
- Servlet application
- 差点跑进奥运会赛场的“人类计算机之父”
- Integer和int的种种比较
- [从头学数学] 第169节 函数的应用
- 同样的错误不能犯两次(三):打招呼
- Oracle数据库和实例的区别
- biaoge
- GeekBand--第六周分享
- Kubuntu(14.04)共享wifi(热点)
- imageloder常见问题
- 链表倒数第k个节点
- Code Sign error: No matching provisioning profile found: Your build settings specify a provisioni...
- 欧几里得算法和唯一分解定理(数论)
- 数据结构与算法(一)