/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/structListNode*reverseBetween(structListNode* pHead,int m,int n ){/*
check input error
*/if(m>n){printf("m can not greater than b");exit(0);}elseif(m >1000){printf("m can not greater than 1000");exit(0);}elseif(n >1000){printf("n can not greater than 1000");exit(0);}structListNode* testNode = pHead;int sum =0;do{if(testNode->val >1000){printf("node val can not greater than 1000");exit(0);}
testNode = testNode->next;
sum ++;}while(testNode !=NULL);if(sum >1000){printf("chian length can not greater than 1000");exit(0);}/*
main code
*/if(pHead ==NULL|| pHead->next ==NULL|| m == n)return pHead;structListNode* before_startNode =NULL;structListNode* startNode = pHead;structListNode* endNode = pHead;//find the start and the end of the intervalfor(int i =1;i<m;i++){
before_startNode = startNode;
startNode = startNode->next;}for(int i =1;i<n;i++){
endNode = endNode->next;}structListNode* beforeNode = startNode;structListNode* Node = startNode->next;structListNode* afterNode = startNode->next->next;//handle the begin and the endif(pHead==startNode)
pHead = endNode;else
before_startNode->next = endNode;if(endNode->next ==NULL);//only 2 elements in this intervalif(Node == endNode){
startNode->next = endNode->next;
endNode->next = startNode;}//inverse the intervalfor(int i =1;i<n-m;i++){//reach the end of this inetervalif(afterNode == endNode){
startNode->next = endNode->next;
endNode->next = Node;}//do the inversion
Node->next = beforeNode;//panning the nodes
beforeNode = Node;
Node = afterNode;
afterNode = afterNode->next;}return pHead;}