首页 > 其他 > 详细

leetCode(1):Reverse Linked List

时间:2015-06-16 17:01:34      阅读:228      评论:0      收藏:0      [点我收藏+]
<pre name="code" class="cpp">/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */



ListNode* reverseList(ListNode* head)
{	
	if(!head)
		return head;
	ListNode* p=head;
	ListNode* q=p->next;	
	if(!q)
		return head;
	ListNode* k=q->next;
	p->next=NULL;
	while(k)
	{
		q->next=p;
		p=q;
		q=k;
		k=k->next;
	}	
	q->next=p;
	return q;//返回头结点
}

leetCode(1):Reverse Linked List

原文:http://blog.csdn.net/walker19900515/article/details/46518015

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!