#include<iostream>
using namespace std;
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(!head){
return nullptr;
}
ListNode *pre = head;
ListNode *cur = head.next;
int i;
while(pre->next !=NULL && i< m){
pre = pre.next;
i++;
}
ListNode *m_pre_node = pre;
ListNode *m_cur_node = pre->next;
j = 0;
while(cur!=NULL && j<n){
m_pre_node->next = m_cur_node->next;
ListNode *next = m_cur_node->next;
m_cur_node->next = head;
head = cur;
cur = next;
j++;
}
return head;
}
};