#include <unistd.h>
class Solution {
public:
ListNode* reverseBetween(ListNode* head, int m, int n) {
ListNode* qq = head;
ListNode* q = head;
ListNode* pre = head;
ListNode* ppre = head;
for (int i = 0; i < m - 2; ++i)
qq = qq->next;
for (int i = 0; i < m - 1; ++i)
q = q->next;
for (int i = 0; i < n -1; ++i)
pre = pre->next;
for (int i = 0; i < n ; ++i)
ppre = ppre->next;
ListNode* x=q;
ListNode* y=q;
ListNode* cur=q->next;
while(cur!=ppre)
{
y=cur;
cur=y->next;
y->next=x;
x=y;
}
qq->next=pre;
q->next=ppre;
if(m==1)
return x;
return head;
}
};