码迷,mamicode.com
首页 > 其他好文 > 详细

206. Reverse Linked List

时间:2016-05-18 17:39:23      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

Reverse a singly linked list.

 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     struct ListNode *next;
 6  * };
 7  */
 8 struct ListNode* reverseList(struct ListNode* head) {
 9     struct ListNode* p;
10     struct ListNode* q;
11     p = head;
12     q = head;
13     if(NULL == head)
14         return head;
15     while(q->next != NULL)
16         q = q->next;
17     while(p != q)
18     {
19         head = head->next;
20         p->next = q->next;
21         q->next = p;
22         p =head;
23     }
24     return head;
25 }

 

206. Reverse Linked List

标签:

原文地址:http://www.cnblogs.com/boluo007/p/5505840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!