Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.
Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
这道题在单链表的反转上做了一点点的修改,要求只反转链表的从第m个到第n个结点。分两步走: 
1. 定位到第m个结点 
2. 进行反转直到第n个结点:没遇到一个结点,就把它插入到第m个结点的前面的位置,然后继续下一个结点。
在操作的过程中需要注意: 
1. 需要一个指向第m个结点前驱结点的指针 
2. 若m==n,则无需操作。
下面贴上代码:
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *reverseBetween(ListNode *head, int m, int n) {
        if (m == n)
            return head;
        ListNode* first = new ListNode(0);
        int len = n - m;
        first->next = head;
        ListNode* p = first;
        while (p&&m > 1){
            p = p->next;
            m--;
        }
        ListNode* q = p->next;
        ListNode* tail = q;
        p->next = NULL;
        ListNode* r = NULL;
        while (q&&len >= 0){
            r = q->next;
            q->next = p->next;
            p->next = q;
            q = r;
            len--;
        }
        tail->next = r;
        return first->next;
    }
};[LeetCode]Reverse Linked List II
原文:http://blog.csdn.net/kaitankedemao/article/details/44539655