鏈表局部翻轉
typedef struct listnode{
int data;
struct listnode* next;
}ListNode;
void ReversePartList(ListNode** list, int m, int n){
ListNode* pre=NULL, *p=NULL, *q=NULL, *t=NULL,*k=NULL;
int i = 1;
p = *list;
while (i <m){
pre = p;
p = p->next;
i++;
}
t = pre;
k = p;
pre = p;
p = p->next;
while (i < n) {
q = p;
p = p->next;
q->next = pre;
pre = q;
++i;
}
k->next = p;
if (t == NULL) {
*list = q;
}
else {
t->next = q;
}
}