206. Reverse Linked List

Posted 米开朗菠萝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了206. Reverse Linked List相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

206. Reverse Linked List

206. Reverse Linked List

206. Reverse Linked List

206. Reverse Linked List

No 206, Reverse Linked List

206. Reverse Linked List